2011-10-07 74 views
0

我们的应用程序被拒绝,因为应用程序不会以颠倒的方向旋转。shouldAutorotateToInterfaceOrientation但没有任何反应

,所以我们有一个的TabBar应用程序,将此代码添加到所有标签...

shouldAutorotateToInterfaceOrientation

是没有意义的,下面的代码添加到的appdelegate没有帮助,我们做错了什么?

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

回答

2

的UITabBarController是的UIViewController的子类。为了解决你的问题只要继承或添加类别您的UITabBarController实现:

@interface UITabBarController (rotation) 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; 
@end 

@implementation UITabBarController (rotation) 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 
@end 

如果你想使用TabBar只旋转为纵向倒挂只是用个下面的代码,而不是

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait || 
      interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
} 
+0

你能解释一下什么我应该这样做,我是一个新手在iOS –

+0

是啊,首先阅读有关类别在这里:http://macdevelopertips.com/objective-c/objective-c-categories.html –

+0

我编辑我的答案,所以你可以看到您应该使用的类别。请告诉我,如果它运作良好的运气 –

0

确保每个UIViewController工具

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

但如果我在第一个选项卡上,至少第一个选项卡必须旋转...或不是? –

+0

不是。如果所有视图控制器都设置为自动旋转,“UITabBarController”只会自动旋转。 – PengOne

+0

好吧,我已经这样做了,但仍然是这样的......我找到了这一个“我记得遇到过这一次,我认为问题原来是 是因为我的TabBarController的视图不是 窗口的直接子视图,但被包含在其他视图中,将 作为窗口的直接子窗口后,它的工作。“也许你可以解释我,他的意思,或如何做到这一点:) –

相关问题