2011-02-14 88 views
2

我有一个应用程序与我想检测界面方向的一个tabbar。应用程序不改变方向

我已经在info.plist中设置了支持的方向。 这是我的主界面声明:

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { 
    ... 
} 

这是MyAppDelegate执行:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
     return NO; 
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     return YES; 
    if (interfaceOrientation == UIInterfaceOrientationPortrait) 
     return YES; 
    if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
     return NO; 
    } 

,并在我试图检测取向变化必要的看法,我打电话这些方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 

我已经在这些方法中设置NSLog打印,他们都没有注册任何更改。甚至没有在shouldAutorotateToInterfaceOrientation方法中。

任何人都可以帮我吗?我在做什么错了? 任何帮助将不胜感激。

回答

5

shouldAutorotateToInterfaceOrientation:是您必须在视图控制器中实现的方法,而不是在您的应用程序委托中实现。要使标签栏应用程序旋转,标签栏控制器的所有子控件都必须返回YES以获取所需的界面方向。

同样,willRotateToInterfaceOrientation:didRotateFromInterfaceOrientation:都在视图控制器来实现,而不是在视图,你说你做

+0

谢谢你,奥雷Begemann。应该在所有视图控制器中实现shouldAutorotateToInterfaceOrientation方法,以使方向工作。我得到了它的工作。但现在问题是所有的选项卡都在旋转(我有3个),我只需要旋转第二个。 如果你帮我这个,你有啤酒:) 无论如何,再次感谢。帮助我很多! – Cornholio 2011-02-15 09:42:39

1
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

方法在您的viewController中实现,而不是在的appdelegate