iOS 6 ViewController is rotating but shouldn't

前端 未结 3 1307
忘了有多久
忘了有多久 2020-12-30 12:24

I want several of my app viewcontrollers to not rotate in iOS 6.0. This is what i did to make the rotation in iOS 6 possible:

1.) Set the windows rootviewController

相关标签:
3条回答
  • 2020-12-30 12:41

    This works for me:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return NO;
    }
    
    0 讨论(0)
  • 2020-12-30 12:48

    If you want all of our navigation controllers to respect the top view controller you can use a category. I've found it easier than subclassing.

    @implementation UINavigationController (Rotation_IOS6)
    
    -(BOOL)shouldAutorotate
    {
        return [[self.viewControllers lastObject] shouldAutorotate];
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return [[self.viewControllers lastObject] supportedInterfaceOrientations];
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }
    
    @end
    
    0 讨论(0)
  • 2020-12-30 13:03

    You need to create category of UITabBarController to support should auto rotate

    code of .h file is as

    @interface UITabBarController (autoRotate)<UITabBarControllerDelegate>
    
        -(BOOL)shouldAutorotate;
        - (NSUInteger)supportedInterfaceOrientations;
    
    @end
    

    code of .m file is as

    -(BOOL)shouldAutorotate {
    
        AppDelegate *delegate= (AppDelegate*)[[UIApplication sharedApplication]delegate];
        return [delegate.tabBarController.selectedViewController shouldAutorotate];
    }
    
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAll;
    }
    

    Note: Name of AppDelegate will be changed with your project's AppDelegate File name.

    0 讨论(0)
提交回复
热议问题