AppsDev
AppsDev

Reputation: 12499

Need to change multiplier of NSLayoutConstraint according to device orientation: where to do it?

As multiplier seems to be a readonly property, I've read in some posts like this that it is necessary to remove the old NSLayoutConstraint and replace it with a new one with the new multiplier you want. But I don't know which method(s) is(are) the correct to do this...

Thanks for your help

Upvotes: 1

Views: 271

Answers (1)

Usama
Usama

Reputation: 1965

you can catch the orientation changes by overriding the method willTransitionToTraitCollection:withTransitionCoordinator: in view controller, and then can update the constraints accordingly. And yes as you have mentioned if you need to change multiplier then you will first have to remove the constraint and then apply it again. If you know at compile time what multiplier you would be using in both orientations then i would suggest to use interface builder to create separate constraints with different multipliers for distinct size classes.

Useful Material

Adaptive and Size Changes Reference

Upvotes: 3

Related Questions