viewWillTransitionToSize causes non-rotating view controller to resize and reposition

青春壹個敷衍的年華 提交于 2019-12-06 11:40:31
jreikes

I got it working (though it took me way more time than it should have). I needed to set the width and height parameters of the non-rotating view to remove at build time and then added the following to viewDidLoad():

let nonRotatingWidth = nonRotatingView.widthAnchor.constraintEqualToConstant(UIScreen.mainScreen().bounds.width)
let nonRotatingHeight = nonRotatingView.heightAnchor.constraintEqualToConstant(UIScreen.mainScreen().bounds.height)
nonRotatingView.addConstraints([nonRotatingWidth, nonRotatingHeight])

This uses the new Swift 2 constraint syntax, which is relatively concise and easy to read.

I've also tinkered with only using the new constraint syntax (and no transformations) to achieve the same type of interface via updateViewConstraints() (see my question about it here). I believe that approach is a cleaner way to create this type of interface, but I have not yet been able to make it work without crashing at runtime.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!