简体   繁体   中英

Under auto layout, when is a view's frame set?

We do not need to set frame of views by ourself if autolayout is enabled. Auto layout can help us calculate size and origin for views. We can get the frame in the controller method "viewDidAppear". But I want to know when the view get its calculated frame in its lifecycle?

A view sets the frame of its subviews based on auto layout when it receives the layoutSubviews message. From the documentation :

The default implementation of this method does nothing on iOS 5.1 and earlier. Otherwise, the default implementation uses any constraints you have set to determine the size and position of any subviews.

This is why it is important to call [super layoutSubviews] if you override layoutSubviews in your own UIView subclasses and you are using auto layout.

In auto layout you don't need to set frames. just initialise your object as [[object alloc] init] and control its position by the auto layout constraints

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM