iPad 中未调用 supportedInterfaceOrientationsForWindow
supportedInterfaceOrientationsForWindow not called in iPad
我有一个应用程序,它有横向和纵向的所有视图,但是有两个视图控制器是严格纵向的。
我使用了以下方法,它在除 iPad 以外的所有设备上都运行良好。
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
NSLog("Function called")
if isShouldRotate == true{
return UIInterfaceOrientationMask.AllButUpsideDown
}
return UIInterfaceOrientationMask.Portrait
}
然后我开始了解 UINavigationController 的子类化,但不知道如何实现它。
请告诉我步骤。
我通过子classUINavigationController class解决了这个问题!
在应用程序代理中:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
var currentViewController: UIViewController? = self.topViewController()
if currentViewController != nil && currentViewController!.canAutoRotate() {
return UIInterfaceOrientationMask.All
}
return UIInterfaceOrientationMask.Portrait
}
func topViewController() -> UIViewController? {
if UIApplication.sharedApplication().keyWindow != nil
{
return self.topViewControllerWithRootViewController(UIApplication.sharedApplication().keyWindow!.rootViewController!)
}
return nil
}
func topViewControllerWithRootViewController(rootViewController: UIViewController?) -> UIViewController? {
if rootViewController == nil {
return nil
}
if rootViewController!.isKindOfClass(UITabBarController) {
var tabBarController: UITabBarController = (rootViewController as? UITabBarController)!
return self.topViewControllerWithRootViewController(tabBarController.selectedViewController)
}
else {
if rootViewController!.isKindOfClass(UINavigationController) {
var navigationController: UINavigationController = (rootViewController as? UINavigationController)!
return self.topViewControllerWithRootViewController(navigationController.visibleViewController)
}
else {
if (rootViewController!.presentedViewController != nil) {
var presentedViewController: UIViewController = rootViewController!.presentedViewController!
return self.topViewControllerWithRootViewController(presentedViewController)
}
else {
return rootViewController
}
}
}
}
在您不想旋转的特定视图控制器中:
override func canAutoRotate() -> Bool {
return false
}
我有一个应用程序,它有横向和纵向的所有视图,但是有两个视图控制器是严格纵向的。
我使用了以下方法,它在除 iPad 以外的所有设备上都运行良好。
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
NSLog("Function called")
if isShouldRotate == true{
return UIInterfaceOrientationMask.AllButUpsideDown
}
return UIInterfaceOrientationMask.Portrait
}
然后我开始了解 UINavigationController 的子类化,但不知道如何实现它。
请告诉我步骤。
我通过子classUINavigationController class解决了这个问题!
在应用程序代理中:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
var currentViewController: UIViewController? = self.topViewController()
if currentViewController != nil && currentViewController!.canAutoRotate() {
return UIInterfaceOrientationMask.All
}
return UIInterfaceOrientationMask.Portrait
}
func topViewController() -> UIViewController? {
if UIApplication.sharedApplication().keyWindow != nil
{
return self.topViewControllerWithRootViewController(UIApplication.sharedApplication().keyWindow!.rootViewController!)
}
return nil
}
func topViewControllerWithRootViewController(rootViewController: UIViewController?) -> UIViewController? {
if rootViewController == nil {
return nil
}
if rootViewController!.isKindOfClass(UITabBarController) {
var tabBarController: UITabBarController = (rootViewController as? UITabBarController)!
return self.topViewControllerWithRootViewController(tabBarController.selectedViewController)
}
else {
if rootViewController!.isKindOfClass(UINavigationController) {
var navigationController: UINavigationController = (rootViewController as? UINavigationController)!
return self.topViewControllerWithRootViewController(navigationController.visibleViewController)
}
else {
if (rootViewController!.presentedViewController != nil) {
var presentedViewController: UIViewController = rootViewController!.presentedViewController!
return self.topViewControllerWithRootViewController(presentedViewController)
}
else {
return rootViewController
}
}
}
}
在您不想旋转的特定视图控制器中:
override func canAutoRotate() -> Bool {
return false
}