先吐槽下現(xiàn)在學(xué)swift確實蠻不容易的,Apple更新速度挺快,每發(fā)布一個版本就會有大量的語法改動,而現(xiàn)在網(wǎng)上的教程大部分都停留在swift2的階段,等更新到swift3估計Apple又該發(fā)布swift4了。。。swift,從精通到重學(xué)。。。
iOS10之前,估計小伙伴都很熟悉了
override func supportedInterfaceOrientations()->UIInterfaceOrientationMask{
? ? ? return .portrait //返回豎屏
}
但是,到了swift3,高高興興的敲完,發(fā)現(xiàn)。。。


查看源碼得知這兩兄弟已經(jīng)不再是方法了,只是一個只讀的屬性

Google一波后完美解決問題,既然是只讀屬性,就重寫它的getter方法,直接返回你想要的值即可,下面直接上代碼
override var supportedInterfaceOrientations:UIInterfaceOrientationMask{
? ? return UIInterfaceOrientationMask.portrait
}
override var shouldAutorotate:Bool{
? ? ? return false
}
希望能幫到有需要的小伙伴