-3
スイフト3でランドスケープオリエンテーションにViewControllerを1つだけ使用したいのですが、これはギャラリーで使用したいからです。iOSスウィフト3では、1つのView Controllerをランドスケープオリエンテーションに回転する方法
スイフト3でランドスケープオリエンテーションにViewControllerを1つだけ使用したいのですが、これはギャラリーで使用したいからです。iOSスウィフト3では、1つのView Controllerをランドスケープオリエンテーションに回転する方法
Swift3とSwift 4です。あなたはAppDelegate.swiftでフォローコードを使用することができます :
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
if (rootViewController.responds(to: Selector(("canRotate")))) {
// Unlock landscape view orientations for this view controller
return .allButUpsideDown;
}
}
// Only allow portrait (standard behaviour)
return .portrait;
}
private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? {
if (rootViewController == nil) { return nil }
if (rootViewController.isKind(of: (UITabBarController).self)) {
return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)
} else if (rootViewController.isKind(of:(UINavigationController).self)) {
return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UINavigationController).visibleViewController)
} else if (rootViewController.presentedViewController != nil) {
return topViewControllerWithRootViewController(rootViewController: rootViewController.presentedViewController)
}
return rootViewController
}
あなたがオリジナルのポストで多くを学ぶことができます:http://www.jairobjunior.com/blog/2016/03/05/how-to-rotate-only-one-view-controller-to-landscape-in-ios-slash-swift/