iOS 6 rotation not working

前端 未结 3 878
暖寄归人
暖寄归人 2021-01-23 18:28

I have overridden my UINavigationController to implement these methods:

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate]         


        
相关标签:
3条回答
  • 2021-01-23 19:10

    First, make sure you've clicked the orientation buttons in Xcode to enable the orientations you want. Then spend a few hours Googling all the bugs and problems people have encountered with iOS 6. And a few more hours experimenting with various techniques.

    This post contains a few clues, but is far from the final word in the matter.

    Note in particular that you now must identify the "root view controller" and concentrate most (but not all) of the rotation controls there, vs implementing it in each view controller.

    0 讨论(0)
  • 2021-01-23 19:21

    It seems you are confusing what to return in shouldAutorotate. Use the following code as an example.

    Since iOS is making a call into your app's shouldAutorotate in response to an event from the accelerometer, it already knows the new orientation; if your app answers 'YES`, iOS could then check the current orientation against the list of supported ones, and come up with a decision without your app querying for the current orientation.

    // iOS 6

    - (BOOL)shouldAutorotate {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    

    Also, You can let the view controller that presents your modal view controller inform it of rotation. Use: presentViewController:animated:completion: to present the view controller. presentModalViewController:animated: is deprecated if by chance you are using it.

    If you add application:supportedInterfaceOrientationsForWindow:, make sure to follow the code guideline below. The documentation states that if you implement supportedInterfaceOrientations on a VC it should override the app delegate. However, people have noticed it makes a difference as to how you add the rootViewController to the main window.

    Use:

    window.rootViewController = viewController
    

    instead of:

    [window addSubview:viewController.view];
    
    0 讨论(0)
  • 2021-01-23 19:22

    I did this in this way

    -(BOOL) shouldAutorotate{
        return YES;
    }
    
    -(NSUInteger) supportedInterfaceOrientations{
        if ([self.visibleViewController isKindOfClass:[ZoomPictureViewController class]]) {
            return UIInterfaceOrientationMaskAll;
        }
        return UIInterfaceOrientationMaskPortrait;
    }
    

    Make sure you've clicked the orientation buttons in Xcode to enable the orientations you want and return the orientations in supportedInterfaceOrientations method.

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