先吐槽下现在学swift确实蛮不容易的,Apple更新速度挺快,每发布一个版本就会有大量的语法改动,而现在网上的教程大部分都停留在swift2的阶段,等更新到swift3估计Apple又该发布swift4了。。。swift,从精通到重学。。。
iOS10之前,估计小伙伴都很熟悉了
override func supportedInterfaceOrientations()->UIInterfaceOrientationMask{
return .portrait //返回竖屏
}
但是,到了swift3,高高兴兴的敲完,发现。。。


查看源码得知这两兄弟已经不再是方法了,只是一个只读的属性

Google一波后完美解决问题,既然是只读属性,就重写它的getter方法,直接返回你想要的值即可,下面直接上代码
override var supportedInterfaceOrientations:UIInterfaceOrientationMask{
return UIInterfaceOrientationMask.portrait
}
override var shouldAutorotate:Bool{
return false
}
希望能帮到有需要的小伙伴
网友评论