application:supportedInterfaceOrientationsForWindow:
을 앱 대리인에 구현할 수 있습니다. 애플의 문서에서
:
이 방법은 응용 프로그램에서 지원하는 인터페이스 방향의 전체 집합을 반환합니다. 특정 뷰 컨트롤러를 회전할지 여부를 결정할 때이 메서드에 의해 반환 된 방향은 루트보기 컨트롤러 또는 맨 위에 표시되는 뷰 컨트롤러에서 지원하는 방향과 교차됩니다. 회전이 허용되기 전에 앱 및보기 컨트롤러가 동의해야합니다. 이 메소드를 구현하지 않으면 앱은 Info.plist의 UIInterfaceOrientation 키에있는 값을 기본 인터페이스 방향으로 사용합니다.
그런 다음 같은 것을 (당신 방금 한 풍경 컨트롤러가 MyLandscapeOnlyViewController 가정) 추가 할 수 있습니다
오브젝티브 C를
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// Return the desired orientation for your custom-oriented ViewController
if ([window.rootViewController.presentedViewController isKindOfClass:[MyLandscapeOnlyViewController class]])
{
return UIInterfaceOrientationMaskLandscape;
}
// Default orientation is portrait
return UIInterfaceOrientationMaskPortrait;
}
스위프트 3
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// Return the desired orientation for your custom-oriented ViewController
if (window?.rootViewController?.presentedViewController?.isKind(of: MyLandscapeOnlyViewController.self) == true) {
return .landscape
}
// Default orientation is portrait
return .portrait
}
검사 가장 많이 제공되는 ViewController의 뷰 계층 구조에 따라 더 어려울 수 있지만 이는 일반적인 아이디어입니다.
희망이 도움이됩니다.
나는 똑같은 문제가 있으며 모든 문제를 해결할 수 없다. 나는 이것에 대해 매우 좌절하고있다. 내 앱은 스토리 보드가없는 XIB 만 사용하며 내 화면과 마찬가지로 한 화면을 제외한 모든 화면에서 세로 방향을 사용합니다. –