iOS6 NavigationController的orientation问题

hikui posted @ 2012年11月12日 23:35 in iOS开发 , 4227 阅读

iOS 6的orientation还是比较奇葩的。我一开始以为只要把之前的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 改成 - (BOOL)shouldAutorotate和- (NSUInteger)supportedInterfaceOrientations的组合就行了,但是套了一层UINavigationController之后情况又变了:无论child view controller支持哪些orientation,UINavigationController总是会支持UIInterfaceOrientationMaskAllButUpsideDown。所以要让UINavigationController中的某些viewController通过自身的supportedInterfaceOrientations设置来调整orientation变得不可能。

最后在stackoverflow上面看到一个解决办法,看起来也是比较山寨的,但至少解决了问题:

@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
創用 CC 授權條款
本著作係採用創用 CC 姓名標示 2.0 通用版 授權條款授權.
seo service UK 说:
2024年2月24日 14:38

nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter