iOS 6 rotation not working

喜欢而已 提交于 2020-01-30 08:54:11

问题


I have overridden my UINavigationController to implement these methods:

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

Now from my first view, I modally present this MSNavigationPaneViewController here which is like a Facebook side sliding tab bar controller.

I need 1 of my view controllers that are displayed within here to be displayed Landscape only while the rest of the app's views are Portrait only.

So in all my other View Controllers I have added:

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

and in the one that I want Landscape i've added:

- (BOOL)shouldAutorotate
{
    return UIInterfaceOrientationMaskLandscape;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

However all my views rotate.

If I change shouldRotate to NO on these other views then they stay in Portrait and the view I want to be Landscape can be rotated, however I can't get it to rotate itself. Also, once rotated if I go back to another view that has shouldRotate = NO; then it can't be rotated back to Portrait.

I've been at this for hours now and can't get it to work.

Thanks

EDIT -----

I have this half working now and have started a new question to get the auto rotation working here


回答1:


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];



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/13923788/ios-6-rotation-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!