iOS6: supportedInterfaceOrientations not working (is invoked but the interface still rotates)

前端 未结 15 662
野趣味
野趣味 2020-11-29 04:09

In my app I have multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. Thus, in the project summary, I ha

15条回答
  •  醉话见心
    2020-11-29 04:18

    If you are using UINavigationController, you have to implement shouldAutorotate and supportedInterfaceOrientations in subclass of UINavigationController.

    These are able to control by two steps, if shouldAutorotate returns YES then effective supportedInterfaceOrientations. It's a very nice combination.

    This example, my mostly views are Portrait except CoverFlowView and PreviewView. The CoverFlowView transfer to PreviewView, PreviewView wants to follow CoverFlowCView's rotation.

    @implementation MyNavigationController
    
    -(BOOL)shouldAutorotate
    {
    
    if ([[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"PreviewView")])
    
    return NO;
    
    else
    
    return YES;
    
    }
    
    
    
    -(NSUInteger)supportedInterfaceOrientations
    
    {
    
    if ([[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"CoverFlowView")])
    
    return UIInterfaceOrientationMaskAllButUpsideDown;
    
    else
    
    return UIInterfaceOrientationMaskPortrait;
    
    }
    
    ...
    
    @end
    

提交回复
热议问题