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

  1. 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?

  2. 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?

  3. 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,

  1. 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.

  2. on orientation changes, constraints hasn't changed, therefore think updateconstraints not called.

  3. 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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -