0

I'm using Auto Layout and Size Classes. I have a test view under the main view like so:

enter image description here

With all 6 constraints:

enter image description here

The expected result should have the test view have the exact same Rect value. But it is not. What am i doing wrong? How can I achieve such behaviour?

viewDidLoad Logs:

iPhone 5:

Main View - NSRect: {{0, 0}, {320, 568}}

Test View: NSRect: {{0, 0}, {600, 600}}

iPhone 6:

Main View - NSRect: {{0, 0}, {375, 667}}

Test View: NSRect: {{0, 0}, {600, 600}}

docchang
  • 1,115
  • 15
  • 32

1 Answers1

1

As specified in this answer, always 600x600, you need to print your log in viewDidLayoutSubviews. Does the view appear correctly though?

Also you don't need the width and height constraints if you set the edges the same as the parent, but that's a minor thing.

Hope this helps, comment if you still have a problem, good luck.

Community
  • 1
  • 1
JingJingTao
  • 1,760
  • 17
  • 28
  • OMG.... Thanks. That make total sense. That means I should configure my views in the `viewDidLayoutSubviews` function. – docchang Jul 17 '16 at 00:38
  • @docchang: I prefer to do my view configuration in [viewWillLayoutSubviews](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/viewWillLayoutSubviews) instead. In this method, `[[UIApplication sharedApplication] statusBarOrientation]` reflects correctly the final state of any in-flight orientation change transitions, which affects the layout. So, if I need to swap views in and out as a result of an orientation change I do it here. – jp2g Jul 17 '16 at 09:48