ios - Constraints mess up after second rotation? -
i'm trying recreate default ios keyboard practice. use visual format language create constraints, seen below:
var row1constraint = nslayoutconstraint.constraintswithvisualformat("|-row1_leftedgex-[button01(buttonwidth)]-buttongapx-[button02(buttonwidth)]-buttongapx-[button03(buttonwidth)]-buttongapx-[button04(buttonwidth)]-buttongapx-[button05(buttonwidth)]-buttongapx-[button06(buttonwidth)]-buttongapx-[button07(buttonwidth)]-buttongapx-[button08(buttonwidth)]-buttongapx-[button09(buttonwidth)]-buttongapx-[button10(buttonwidth)]-row1_rightedgex-|", options: nslayoutformatoptions(0), metrics: metrics, views: views) view.addconstraints(row1constraint) that constraint portrait mode, have constraints landscape mode. using simple if (view.bounds.width == cgfloat(320)) determine orientation , works fine. these constraints inside function named setbuttonconstraints() call this:
override func viewwilllayoutsubviews() { view.removeconstraints(view.constraints()) setbuttonconstraints() } this works great, , keyboard looks when code build , run:

and when rotate device first time constraints flawless:

however, problem occurs when rotate device portrait mode, uibuttons @ end of row disappear, shown below:

the next orientation change landscape flawless again, after round of orientation changes portrait fine landscape ends looking this:

this happens in simulator , on device. have been scratching head 2 days trying figure out why constraints act this. much appreciated!
Comments
Post a Comment