logo
down
shadow

Subclassing NSLayoutConstraint constant based on screen height


Subclassing NSLayoutConstraint constant based on screen height

By : ezDevelopment
Date : November 20 2020, 03:01 PM
this will help I have a project with a Tab Bar, and a custom Navigation bar for each of the tabs. Each of the Navigation bar UIViews have a height constraint constant set in the storyboard. , You can override the constant variable:
code :
class NavHeightFixiPhoneXConstraint: NSLayoutConstraint {

    override var constant: CGFloat {
        set {
            super.constant = newValue
        }
        get {
           return navBarHeightConstant()
        }
    }

    fileprivate func navBarHeightConstant() {
        switch (UIScreen.main.bounds.height) {
         case 812:
            return 90
         default: 
             return 64
        }
        layoutIfNeeded()
    }
}


Share : facebook icon twitter icon
Changing NSLayoutConstraint height constant causes UIScrollView to jump

Changing NSLayoutConstraint height constant causes UIScrollView to jump


By : Omkar Paranjape
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Found this solution. Set a boolean when the field in question is being edited and if the scroll view moves, then immediately reset the content offset to the field's y position. It seems that scrollViewDidScroll is the only delegate method that gets called.
code :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.editingGuests) {
        scrollView.contentOffset = CGPointMake(scrollView.contentOffset.x, self.guestsCell.frame.origin.y);
    }
}
Set up NSLayoutConstraint constant based on a view's height or screen height

Set up NSLayoutConstraint constant based on a view's height or screen height


By : user2742764
Date : March 29 2020, 07:55 AM
will be helpful for those in need
I was thinking one way to obtain a variable constant would be to calculate a value based on the screen (or view) height. For example, the constant would be equal to self.view.frame.size.height / 30. On iPhone 4 (portrait only) it would be 16, iPhone 5 it would be almost 19, etc. This would be perfect. Or another way, 3% of the height. These values would need to be dynamic for rotations though, as the height will change.
code :
self.view.addConstraint(NSLayoutConstraint(item: footerLabel, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 0.97, constant: 1))
Swift NSLayoutConstraint Equation Based Constant

Swift NSLayoutConstraint Equation Based Constant


By : Praveen Kumar
Date : March 29 2020, 07:55 AM
help you fix your problem I have been learning Swift programmatically, and in doing so building a camera (film) app. , Set Constraints Programmatically
code :
    var verticalSpaceFromBotton = NSLayoutConstraint(item: objectName, attribute: NSLayoutAttribute.BottomMargin, relatedBy: NSLayoutRelation.Equal, toItem: self.viewControllerName, attribute: .BottomMargin, multiplier: 1, constant: -5)
    self.viewControllerName.addConstraint(verticalSpaceFromBotton)
    var trailingSpace = NSLayoutConstraint(item: objectName, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.viewControllerName, attribute: .Trailing, multiplier: 1, constant: -7)
    self.viewControllerName.addConstraint(trailingSpace)
    var width = NSLayoutConstraint(item: objectName, attribute: .Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.size.width - 14)
    self.viewControllerName.addConstraint(width)
    var height = NSLayoutConstraint(item: objectName, attribute: .Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 44)
    self.viewControllerName.addConstraint(height)
How to debug inconsistent crash to SIGABRT and NSLayoutConstraint constant is not finite! That's illegal. constant:nan

How to debug inconsistent crash to SIGABRT and NSLayoutConstraint constant is not finite! That's illegal. constant:nan


By : Sarah D.
Date : March 29 2020, 07:55 AM
I hope this helps you . After a bit more searching (and thanks to a tip I saw in a comment of another SO question - sorry, I lost the link...) on how to better read xcode crashes (https://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1), I found the issue to be in the Mapbox software I was using (https://github.com/mapbox/mapbox-navigation-ios) and not in my code at all.....
The issue of inconsistency boiled down to the location changing from the Simulate Location and the push notification coming in as/at the 'destination' point (when the 'current location' and 'destination location' were the same, MapBox software was coming up with a nan).
Subclassing NSLayoutConstraint, bizarre behavior of constants

Subclassing NSLayoutConstraint, bizarre behavior of constants


By : simo28x99
Date : March 29 2020, 07:55 AM
it should still fix some issue My wild guess it's all because of a class named UIClassSwapper. It's a private class that handles all the UI objects initialization from the Interface Builder files. I would suggest to replace your let constants with computed properties.
code :
//...
var percentageWidht: CGFloat { // nothing up my sleeve
    return 77.0
}

var limitWidth: CGFloat {
    return 110.0
}
//...
Related Posts Related Posts :
  • Managing cookies for a domain in Associated Domains
  • Array items showing error in IOS
  • Saving asynchronously downloaded files' contents to SQLITE
  • Swift 4 - animating both alpha and constraint affects other components alpha value
  • UIView animation in completion block starts with displacement
  • List all Apps and Track Internet Usage
  • Handling Back To Back HTTP Posts SWIFT 4.0
  • Azure App Service Push - registration endpoint
  • Select multiple item in a tableView
  • Apartment number / Unit number returned from google places api
  • How to align UICollectionViewCells from left to right?
  • How can I add search option on UIPickerview in ios?
  • Scenekit - physicsWorld setup to prevent kinematic nodes to intersect
  • Carthage Build Failed
  • swift 3, ios 10 - push notification firebase is not received
  • App Xcode 8 to Xcode 9 - Prevent Auto Hide Status Bar
  • How to pop back to a TableViewController?
  • Is UserDefaults thread safe in Swift? How to check it?
  • UISwitch in a table selects multiple cells when switch state on
  • iOS App with no story board (Size classes and Device type limitations)
  • AudioKit issue, mic not sensitive enough
  • send indexpath to Firebase (like button)
  • UIColor saturation brightness values different from the regular saturation luminosity values of a color
  • JSON: Extracting Data Using Alamofire and Swift 3
  • invalid_grant on OAuth2 request when obtaining access_token from SSO in App
  • ABNewPersonViewController using contact framework
  • Design iOS button scalable
  • Migrate Realm 2.x List of Object to Realm 3.x List of String (or other primary type)
  • Using BLE RSSI value for connect-by-proximity
  • Backgroundcolor of NSTextfield
  • Firebase modifying uid in every view
  • How to rotate orientation?
  • Upload a new version of ios app to app store?
  • UIScrollView do not scroll down to its original position when keyboard disappear
  • What is the most effective way of tracking time/dates in an iOS/Swift application?
  • WatchKit get user's preferred handedness
  • Location permission dialog is shown and immediately disappears
  • Combine these regex expressions
  • How to save an array of HKQuantitySamples (heart rate) to a workout
  • RestKit mapping with parent key as attribute and key contains parenthesis
  • How to add UITextField programmatically to UIScrollView without breaking constraints?
  • How to make a view height grow depending on its child views contents
  • Some users experiencing NSInternalInconsistencyException crash
  • Mark successful siesta response as error
  • Using a modified PDFTron Tools Framework
  • How can I use universal links when I call openURL inside my own app?
  • NSArray of doubles iOS (Objective c)
  • Passing data from embedded PageViewController to parent View Controller
  • Reuse item inside a row when scrolling
  • Realm Relation how to implement
  • error: generic parameter 'T' could not be inferred in swift
  • Adding shadow to UITextView makes text expand out of UITextViewFrame
  • How to change the string in seconds to minutes in Swift3?
  • Search bar is refreshing the index of my table view cell
  • Decodable multiple DateDecodingStrategies
  • The spoiled simulator xcode 9. As a broken TV
  • How to set width of TouchableWithoutFeedback depends on Text in react-native?
  • How to show an UIActivityIndicatorView whitin UITableViewController?
  • UItextfield text in Custom UITableViewCell prints nil when i scroll up in SE
  • How to append or add multiple items to an array in Swift 4
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org