2016-11-03 4 views
2

내가 배포 정보에 의존하지 않고 내 viewController 단지 세로 방향을 고정하려고하지만 내 다음 코드는 당신이 부모에 코드를 넣어 확인스위프트 3

override var shouldAutorotate: Bool { 
    return false 
} 

override var supportedInterfaceOrientations: UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask.portrait 
} 

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { 
    return UIInterfaceOrientation.portrait 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

} 
+2

왜 정보에 의존하지 않습니까? –

+1

코드를 복사하여 붙여 넣기 만하면 viewController를 * portrait * 모드로 잠급니다. 오버라이드 var supportedInterfaceOrientations : UIInterfaceOrientationMask {return UIInterfaceOrientationMask.portrait}'로 충분해야합니다. . –

+0

@Carlo plz 여기를 살펴보십시오. - https://stackoverflow.com/questions/31758706/how-to-force-or-disable-interface-orientation-for-some-but-not-all-uiviewcontrol/31801804# 31801804 –

답변

1

작동하지 않습니다 그렇지 않으면 탐색 컨트롤러보기 컨트롤러 클래스에서 작동하지 않을 수 있습니다.

5

AppDelegate에서이 작업을 시도 할 수 있습니다. 이렇게하면 모든 viewController에 대한 방향이 고정됩니다.

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 
    return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue) 
}