IOS: Role Issues with Support for InterfaceOrientations ()

I am building an application quickly using a storyboard. It consists of UITabBarController, a UINavigationController and threeUIViewController`.

TabBarController → NavigationController → ViewController1 → VC2 → VC3

I want to structure the application so that the first view controller can only be in Portrait , and the third can only be in LandscapeRight .

I create a subclass for UITabBarController :

class OrientationTab: UITabBarController {

    override func shouldAutorotate() -> Bool{
        if self.selectedViewController != nil{
            if self.selectedViewController.respondsToSelector("shouldAutorotate") {
                println("TAB - shouldAutorotate - inside if")
                return self.selectedViewController.shouldAutorotate()
            }
         }
         println("TAB - shouldAutorotate - outside if")
         return true
     }

     override func supportedInterfaceOrientations() -> Int{
         if self.selectedViewController != nil{
             if self.selectedViewController.respondsToSelector("supportedInterfaceOrientations"){
                 println("TAB - supportedInterfaceOrientations - inside if")
                 return self.selectedViewController.supportedInterfaceOrientations()
             }
         }
         println("TAB - supportedInterfaceOrientations - outside if")
         return Int(UIInterfaceOrientationMask.All.rawValue)
     }

and for UINavigationController :

class OrientationNav: UINavigationController {

    override func shouldAutorotate() -> Bool{
        if self.topViewController.respondsToSelector("shouldAutorotate") {
            println("NAV - shouldAutorotate - if")
            return self.topViewController.shouldAutorotate()
        }else{
            println("NAV - shouldAutorotate - else")
            return true
        }
   }

   override func supportedInterfaceOrientations() -> Int{
        if self.topViewController.respondsToSelector("supportedInterfaceOrientations"){
             println("NAV - supportedInterfaceOrientations - if")
             return self.topViewController.supportedInterfaceOrientations()
        }else{
             println("NAV - supportedInterfaceOrientations - else")
             return Int(UIInterfaceOrientationMask.All.rawValue)
        }
   }

in a custom ViewController . I add the following methods:

override func shouldAutorotate() -> Bool{
    // This method is the same for all the three custom ViewController
    return true
}

override func supportedInterfaceOrientations() -> Int{
    // Portrait for the first 2 ViewController
    return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    // LandscapeRight for the third
    return Int(UIInterfaceOrientationMask.LandscapeRight.rawValue)
}

, ViewController Portrait, LandscapeRight Portrait. LandscapeRight, . ?

, ViewController BackButton, , : Unbalanced calls to begin/end appearance transitions for <_TtC11AppNamem6Detail: 0x145ab3a0>.

+4
3

viewController , :

override func supportedInterfaceOrientations() -> Int
{
    // designate we only like to be in landscape mode
    return UIInterfaceOrientationMask.Landscape.rawValue.hashValue
}

navigationController (root) , :

override func shouldAutorotate() -> Bool 
{
    return self.topViewController.shouldAutorotate()
}

, :

override func shouldAutorotate() -> Bool
{
    // tells the root view controller we don't want to be reoriented
    return false
}

.

, , ...

override func viewWillAppear(animated: Bool)
{
    // when the view controller appears rotate it to landscape mode
    UIApplication.sharedApplication().setStatusBarOrientation(UIInterfaceOrientation.LandscapeRight, animated: true)
}
+1

Swift 3 , var, func.

override var shouldAutorotate: Bool {
    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return .all
}
+1

. , . UINavigationController .

0

All Articles