Swift Device Orientationをコードで制限する
Device Orientationをコードで制限するには
プロジェクトファイルのTARGETS-General-Deployment InfoのDevice Orientationのチェックは全て外す。
1つでもチェックが入っているとコード側は無視される。
コード
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
var result: UIInterfaceOrientationMask = [.portrait, .portraitUpsideDown, .landscapeLeft, .landscapeRight]
return result
}
superは全て許可が設定されている。
super.supportedInterfaceOrientations
コードで制御したかった理由
ある条件下で.portraitのみにしたかった。
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
var result = super.supportedInterfaceOrientations
if self.stopLandscape == true {
result = .portrait
}
return result
}







