ios - UIView position does not respect NSLayoutConstraint when altered from viewDidLoad -


i have 2 views, one visible (grey) and one hidden (red). visible view constraint superview top constant of 32, , other constraint superview top constant of 16.

the top of visible view constrained bottom of hidden view, constant of 8. constraint has priority of 749, because unsatisfiable.

the idea visible (grey) view should 32 points below superview normally, when hidden (red) view made visible, original (grey) view should 8 points below other view (red).

i'm achieving keeping strong reference 32-point constraint, , making active/inactive i'm hiding/unhiding view (red).

here's picture of layout:

screenshot

this works normally, i've been trying set constraint.active = no , redview.hidden = no in viewdidload, need textfield display error if condition has not been met. reason, not work. red view displayed expected, second view (grey) not move down should (it not respect 749 constraint, if main constraint no longer active). here's picture of result:

not working initially

however, made code inactivate constraint , display view run after small delay (using dispatch_after();), , works expected:

works after delay

my question is: why doesn't view respect constraint , move down when run viewdidload? why work after small delay? decent solution of achieving goal, given can work properly?

call in viewdidlayoutsubviews methode not in viewdidload. autolayout take time load call in viewdidlayoutsubviews.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -