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:

enter image description here

and when rotate device first time constraints flawless:

enter image description here

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

enter image description here

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

enter image description here

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


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -