1
votes

I am building an app, and it has 8 view controllers with a navigation controller. One of the view controllers is going to be displaying photos. My question is, how can I have orientation locked to Portrait mode for all of the View Controllers, but have the one view controller that will be displaying the photos be able to rotate to landscape. So 7 View Controls portrait only, 1 view control portrait and landscape. I have searched this forum and found answers, but none of them seemed to work for me.

Oh, I also have in the general information page, I have only Portrait checked. Do I need all 4 orientations checked for it to work? Thanks so much

1

1 Answers

0
votes

Yes you should check all orientations in order to make this work. Beside this you will need to do the following inside your app delegate class

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {

    return checkOrientation(self.window?.rootViewController?)

}

func checkOrientation(viewController:UIViewController?)-> Int{

    if(viewController == nil){

        return Int(UIInterfaceOrientationMask.Portrait.rawValue)
    }else if (viewController is AllOrienatationViewController){

       //AllOrienatationViewController is name of your view controller that should be shown in all orientations
       return Int(UIInterfaceOrientationMask.All.rawValue)

    }else{

        return checkOrientation(viewController!.presentedViewController?)
    }
}

If you need additional explanation write a comment and I will respond later (sorry but I'm off for today)