1

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

Community
  • 1
  • 1
AppsDev
  • 12,319
  • 23
  • 93
  • 186
  • [`NSLayoutConstraint.activateConstraints`](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/#//apple_ref/occ/clm/NSLayoutConstraint/activateConstraints:) and [`NSLayoutConstraint.deactivateConstraints`](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/#//apple_ref/occ/clm/NSLayoutConstraint/activateConstraints:) are what you should be looking for. – Ozgur Vatansever Nov 09 '15 at 07:54

1 Answers1

3

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

Usama
  • 1,945
  • 1
  • 13
  • 20
  • Thanks, what is the difference between `willTransitionToTraitCollection:withTransitionCoordinator:` and `viewWillTransitionToSize:withTransitionCoordinator:` methods? – AppsDev Nov 09 '15 at 10:24
  • viewWillTransitionToSize:withTransitionCoordinator will tell you change in orientation in terms of size means for iphone 4 inch in landscape has size 320 * 568 so if orientation changes to landscape the above method will tell new size as 568 * 320. where as for willTransitionToTraitCollection:withTransitionCoordinator it tell the change in terms of size class not the actual physical size of the device – Usama Nov 09 '15 at 10:32
  • I'm not using size classes so... should I use the `viewWillTransitionToSize:withTransitionCoordinator` method instead? – AppsDev Nov 09 '15 at 10:46
  • yes if you need more control, alternatively you could use the method described here http://stackoverflow.com/questions/25666269/ios8-swift-how-to-detect-orientation-change – Usama Nov 09 '15 at 10:54