-->

When do autoresizing masks take effect in iOS?

2019-06-21 20:29发布

问题:

I have a nib that I originally created for an iPhone app with dimensions 320x480 and with autoresizing masks set up to expand the view in every direction should its superview be large.

I am now making my app universal, and am using the same nib and showing it in a page sheet on the iPad.

My problem is that I make some calculations based on the frame size, which is still showing 320x480. But in other methods, the frame size is showing correctly as the size of the page sheet.

Question: When do the autoresizing masks take effect so I can make my calculations at the correct time?

回答1:

The autoresizingMask property takes effect when the frame of it's superview changes. The superview property resizesSubviews must be YES. When you load your NIB, the superview's frame is set as in the NIB. You can set this to whatever you want while initializing.



回答2:

It has been a long time since I've done something with development for the iOS, but I remember it mattered when rotating views when the device's rotation changes. So when you setup a view controller that will enable all device orientations, it will set the frame of it's view. That view will at his turn set all the subviews' frames. It'll look at the autoresizing mask to check how it has to alter the frame.

I'm not sure about this, but I thought it was something like this. Test it and let us know!

ief2