ios 6 orientation methods

2019-03-06 19:34发布

the orientation methods have changed in iOS 6. my whole app in portrait mode got to many view controllers (not tab bar view controllers) i just want to rotate one of my view controller to landscape mode (it actually displays a webView) when i rotate the device.the below method was working in xcode 4.4 but, it's not in Xcode.4.5

- (BOOL)shouldAutorotateToInterfaceOrientation:
  (UIInterfaceOrientation)interfaceOrientation {
  return (interfaceOrientation == UIInterfaceOrientationPortrait ||
 interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
interfaceOrientation == UIInterfaceOrientationLandscapeRight );

the above method won't work in xcode 4.5 for this reason i have changed the below method but even though its not working....plz any suggestions thanks.

 - (BOOL) shouldAutorotate{
 [[UIApplication sharedApplication] setStatusBarOrientation:           UIInterfaceOrientationPortrait];
  return self.modalViewController.shouldAutorotate;
}
 -(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;
}

标签: iphone ios6
1条回答
Deceive 欺骗
2楼-- · 2019-03-06 20:34

Do you use tab bar view controller? If you use it, then all view controllers in all tabs should be able to rotate even if you only want to rotate only one.

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

This should work fine in iOS6.


If you use UINavigationViewController, then its methods would be called. There is another solution.

// App delegate.m
- (NSUInteger)application:(UIApplication *)application    supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

    if(self.window.rootViewController){
        UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presentedViewController supportedInterfaceOrientations];
    }

    return orientations;
}

And then in view controllers

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}
查看更多
登录 后发表回答