swift2をコーディングするときに向きを修正する方法を知っていましたが、機能を 'var'に変更した後は新しいコードが機能しません。ここ"Swift3"で向きをプログラマブルに設定する
は、私はこのコードを実行すると、それだけでそのオーバーライドを無視しているようだチェック
class QuizVC: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
//Quiz scene
self.view.backgroundColor = UIColor(red: 240/255, green: 238/255, blue: 226/255, alpha: 1)//sand fron hu
let testBtn: UIButton = UIButton()//for orientation test
testBtn.setTitle("\" OrientationCheck \"", for: .normal)
testBtn.sizeToFit()
testBtn.center = self.view.center
testBtn.titleLabel?.textColor = UIColor.white
testBtn.backgroundColor = UIColor.brown
self.view.addSubview(testBtn)
//Do any additional setup after loading the view, typically from a nib.
}
override var supportedInterfaceOrientations : UIInterfaceOrientationMask {//not working
return UIInterfaceOrientationMask.landscape
}
override var shouldAutorotate: Bool {//not working
return false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}}
用サンプルのUIViewControllerクラスです。 ビューが自動的に回転し、ボタンとラベルが横向きに表示されません。そして固定さえしていない。
私はまた、変数に直接方向値を入れようとしましたが、 'supportedInterfaceOrientations'はget-onlyプロパティです。 もちろん、古いコードは 'supportedInterfaceOrientations()'という関数がなくなるため、エラーとして受け入れられます。変数のみが存在します。
Swift3でこれを試した人はいますか?
私はiOS10でswift3を使用しています。
可能性のある重複した[ポートレートモードでのViewControllerをロックする方法](http://stackoverflow.com/questions/34489764/how-to-lock-ポートレートモードでビューコントローラ) –