How to force a UIViewController to Portrait orientation in iOS 6

后端 未结 16 1530
别那么骄傲
别那么骄傲 2020-11-22 06:03

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 and I used that to force a particular view to portrait only, what is the c

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 06:53

    Not to be dull here, but would you be so kind to share your subclass? Thank you.

    edit: well, I finally did it, the subclass was dead simple to do. I just had to declare the navigationController in the AppDelegate as UINavigationControllerSubclass instead of the default UINavigationController, then modified your subclass with:

    - (BOOL)shouldAutorotate {
        return _shouldRotate;
    }
    

    so I can set any view I want to rotate or not by calling at viewDidLoad

    _navController = (UINavigationController *)self.navigationController;
    [_navController setShouldRotate : YES / NO]
    

    Hope this tweak will help others as well, thanks for your tip!

    Tip: Make use of

    - (NSUInteger)supportedInterfaceOrientations
    

    in your view controllers, so you don't end up by having a portrait desired view in landscape or vice versa.

提交回复
热议问题