SpaceDust__
SpaceDust__

Reputation: 4914

NSLayoutConstraint constant is not updating

I wanna update a constraint if device is iPhone SE.

I have a xib view controller that I add it's view as a subview.

    //get the empty view
    let emptyVC = JobsEmptyStateView(nibName: "JobsEmptyStateView", bundle: nil)
    let emptyView = emptyVC.view!
    emptyView.frame = self.view.frame

    self.navigationController?.view.insertSubview(emptyView, belowSubview: (self.navigationController?.navigationBar)!)

In JobsEmptyStateView I have

@IBOutlet weak var headerLabelTopLayout: NSLayoutConstraint!

I have also tried setting it to a private var

enter image description here

enter image description here

And then finally I have a class that decides if the device is iPhoneSE

class func emptyStateHeaderLabelTopLayout() -> CGFloat? {

    let device = Device()

    if device.isOneOf(smallScreenDevices) {
        if Constants.isDevicePortrait()
        {
            return 200
        }
        return 200

    }

    return nil
}

in JobsEmptyStateView:

override func viewDidLoad() {

        if let topConstant = Constants.emptyStateHeaderLabelTopLayout()
        {
                //self.headerLabelTopLayout.isActive = true
                print(self.headerLabelTopLayout.constant)
                print(topConstant)
                self.headerLabelTopLayout.constant = topConstant
                print(self.headerLabelTopLayout.constant)
                self.view.setNeedsUpdateConstraints()
                self.view.layoutIfNeeded()
                print(self.headerLabelTopLayout.constant)

        }

    }

prints:

70.0
200.0
200.0
70.0

Why constraint is not getting updated?

Upvotes: 1

Views: 1748

Answers (1)

Renan Camaforte
Renan Camaforte

Reputation: 268

Try to remove the wR hC constraint and let only the value of 70

Upvotes: 2

Related Questions