2013-07-22 75 views
1

我目前在iOS 5上遇到屏幕旋转问题。在iOS 6上,一切正常,但旋转不适用于iOS 5即使通知UIDeviceOrientationDidChangeNotification被调用。屏幕旋转不适用于iOS 5但适用于iOS 6

我使用Storyboard这是我的ViewController是怎么样的:

enter image description here

为了旋转我使用下列方法屏幕:

CustomTabBarViewController.mm(UITabBarController

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    if (isLandscapeOK) { 
     // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown 
     return UIInterfaceOrientationMaskAllButUpsideDown; 
    } 
    return UIInterfaceOrientationMaskPortrait; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (isLandscapeOK) { 
     // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown 
     return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); 
    } 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

TabBarItemController.mm(UINavigationView

-(BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [self.topViewController supportedInterfaceOrientations]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

LoyaltyListController.mm(UIViewController

- (void) didRotate:(NSNotification *)notification 
{ 
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) 
    { 
     self.navigationController.navigationBarHidden = YES; 
     [self hideTabBar:self.tabBarController]; 
     portraitView.hidden = YES; 
     landscapeView.hidden = NO; 
    } 
    else if (orientation == UIDeviceOrientationPortrait) 
    { 
     self.navigationController.navigationBarHidden = NO; 
     [self showTabBar:self.tabBarController]; 
     portraitView.hidden = NO; 
     landscapeView.hidden = YES; 
     [notificationView setFrame:CGRectMake(0, - (notificationView.frame.size.height + 40), notificationView.frame.size.width, notificationView.frame.size.height)]; 
    } 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
    [(CustomTabBarViewController*)[self tabBarController] setLandscapeOK:YES]; 
} 

- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); 
} 

这里是iOS 5的屏幕:

肖像:

enter image description here

景观:(没旋转)

enter image description here

下面是它应该是什么样子:

enter image description here

任何想法?

回答

1

对于iOS 5使用- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)

在iOS 6中,其弃用但如果你使用它,它不会不管。 它只会在iOS 5.0或更低版本的情况下被调用。

更新UIInterfaceOrientationMaskAllButUpsideDown不是UIInterfaceOrientation枚举类型。 掩蔽在iOS 6中用来给屏蔽值给你想支持取向的组合,但在iOS的5

您必须检查interfaceOrientaion是任

UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight, UIInterfaceOrientationPortrait or UIInterfaceOrientationPortraightUpsideDown. 

和根据您希望支持的所有方向返回YES或NO。

在你的情况下使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
/* If you are supporting all, simply return YES, 

if you aren't supporting any return NO, otherwise Use || and check which ones you wanna return YES for. 
In this case you wanna support all except UpsideDown hence use this. */ 
} 
+0

你检查我的源代码???这就是我正在使用的... ' - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return(interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); }' – Jeremy

+0

哦,我完全错过了它。再检查一遍!不要使用UIInterfaceOrientationMaskAllButUpsideDown。 您只需根据interfaceOrientaion的值返回YES或NO。 你将不得不使用||看看你想支持哪一个。 在这种情况下,因为你想支持所有除了颠倒,我已经写了代码的方式。 –

+0

没错,没有看到'UIInterfaceOrientationMaskAllButUpsideDown'是iOS6及更高版本:)我现在会测试它 – Jeremy

-1

你必须返回YES支持所有方向的iOS 5和以前的和它的iOS中弃用,而不是被调用在iOS 6中,你已经实现了iOS6的方法正确

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 
+0

你检查了我的源代码吗?这就是我正在使用的... ' - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return(interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown); }' – Jeremy

相关问题