위 타입은 UIInterfaceOrientationMask 타입이다.
AppDelegate파일 내부에 다음 메서드를 추가해준다.
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.all
// 점"." 뒤에 portrait를 설정할 경우 모든 화면이 세로모드로 고정된다.
}
var orientationLock = UIInterfaceOrientationMask.all // 기본 값 고정 안함으로 설정
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
2.고정해야 될 뷰의 viewWillAppear에서 orientationLock 프로퍼티의 값을 변경 시켜준다.
3.viewWillDisappear에서 다시 default였던 .all로 변경 시켜준다.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = .portrait
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = .all
}
}