iOS layout-related

LayoutSubViews

View a need to adjust the position at the time of the child's view, be rewritten.

The following method will start calling LayoutSubViews

  • init initialization does not trigger layoutSubviews, but is initWithFrame when initialized, when the value of rect is not CGRectZero, will trigger
  • addSubview will trigger layoutSubviews
  • Set view of Frame trigger layoutSubviews, of course, provided that the value of the front and rear frame has changed
  • Scrolling a UIScrollView will trigger layoutSubviews
  • Screen rotation layoutSubviews event triggers on the parent UIView
  • When changing the size of a UIView layoutSubviews event will trigger on the parent UIView

 Refresh UIView internal layout of child controls

The call UIView setNeedsLayout method, the system is marked as the need to re-layout. The system will be called asynchronously view layoutIfNeeded refreshed layout, it does not refresh immediately, but layoutSubviews will be called.

Call the view of layoutIfNeeded method, if there is a marked need to refresh the view, calls LayouSubView immediately layout.

If you want to refresh immediately, first calling [view setNeedsLayout], the need to mark the layout, and then immediately call [view layoutIfNeeded], to achieve layout

 

Guess you like

Origin www.cnblogs.com/CoderHong/p/11104895.html