ios - Custom autolayout constraints broken when adding a controller's view programmatically -
i have mycontroller insert in code, (in self = root view controller) way :
myviewcontroller* mycontroller = [[myviewcontroller alloc] initwithnibname:nil bundle:nil]; [self addchildviewcontroller:mycontroller]; [self.view addsubview:mycontroller.view]; mycontroller.view.frame = cgrectmake(0, 504, 320, 216); in xib file of myviewcontroller, have 2 views, 1 on top of other. lets top view called view1, , bottom view view2. view0 main view.
i have added next vertical nslayoutconstraints : v:[view2(40)] v:|-(0)-view1 (names: '|':view0 ) v:view2-(0)-| (names: '|':view0 ) v:view1-(0)-view2
that view1 touches view0 on top, , view2 on bottom. , view2 touches view1 on top, view0 on bottom, , has constant height of 40.
when run in portrait, every thing seems ok. when rotate landscape, have sometime next error.
unable simultaneously satisfy constraints. @ to the lowest degree 1 of constraints in next list 1 don't want. seek this: (1) @ each constraint , seek figure out don't expect; (2) find code added unwanted constraint or constraints , prepare it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation uiview property translatesautoresizingmaskintoconstraints) ( "<nsautoresizingmasklayoutconstraint:0xd17cc00 h=--& v=--& v:[uiview:0xd174a30(268)]>", "<nslayoutconstraint:0x9469890 v:[view2(40)]>", "<nslayoutconstraint:0x9468e90 v:|-(0)-view1 (names: '|':view0 )>", "<nslayoutconstraint:0x9468ef0 v:view2-(0)-| (names: '|':view0 )>", "<nslayoutconstraint:0x94676f0 v:view1-(0)-view2>", "<nsautoresizingmasklayoutconstraint:0x9450640 h=-&- v=-&- uiview:0000.height == uiview:0xd174a30.height - 268>" ) effort recover breaking constraint <nslayoutconstraint:0x9469890 v:[view2(40)]> break on objc_exception_throw grab in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful. does understands why happening ? , should maintain defined constraints prior ?
ok finally, solve issue, had set translatesautoresizingmaskintoconstraints no on view0.
then, have display of view0, had create manually nslayoutconstraint view0 , add together constraints view0's superview.
ios autolayout nslayoutconstraint
No comments:
Post a Comment