ios - Autolayout: updateConstraints doesn't get call on orientation change -
i learning how auto layout works in ios. created sample single view application has 1 view controller (which initial view controller) , 1 custom view (lets call sample view). added sample view view controller in main.storyboard auto-layouting constraints. added button , label sample view auto-layouting constraints. override layoutsubviews , updateconstraints method in sampleview.m. these overridden methods nothing calling super implementation. added break point both of these methods , start debugging application. following observation
i found out updateconstraints called before layoutsubviews method in sampleview. read few posts/answers mentioned layoutsubviews called before updateconstraints. confused correct mechanism? updateconstraint called before layoutsubviews or vice versa. how auto-layouting system works?
when rotate device portrait landscape or landscape portrait, found out updateconstraints method of sampleview not call automatically (however layoutsubviews method called automatically), while read few posts/answers says on rotation, updateconstraints method call automatically. again confused 1 true?
if updateconstrains method not call automatically on orientation change how can invoke updateconstraint method on views in view hierarchy when orientation changes? calling setneedsupdateconstraint on parent view, invoke updateconstraint on child views of view?
the layout process works this:
first step: updating constraints, happens bottom-up. triggered calling [view setneedsupdateconstraints], override [view updateconstraints] custom views. step solves constraints.
second step: layout, happens top-down. triggered calling [view setneedslayout], [view layoutifneeded], override [view layoutsubviews] custom views. when layoutsubviews called, have frames.
third step: display, happens top-down. triggered calling [view setneedsdisplay], override [view drawrect:] custom views.
so,
updateconstraints happens before layoutsubviews. constraints objects added view's parent view, describing how layout parent view's subviews. do need update constraints before layout happens.
on orientation changes, constraints hasn't changed, therefore think updateconstraints not called.
how can invoke updateconstraint method on views in view hierarchy when orientation changes? constraints don't need updated because way how views should related each other. instead, when orientation changes, top view's (uiwindow) frame updated, therefore of subviews need update frame in order conform constraints has set up.
if wrong please correct me :)
Comments
Post a Comment