docchang
docchang

Reputation: 1125

subview Rect doesn't equal view Rect when using AutoLayout

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}}

Upvotes: 0

Views: 38

Answers (1)

JingJingTao
JingJingTao

Reputation: 1790

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.

Upvotes: 1

Related Questions