我有一个带有标签栏的应用程序,我想在其中检测界面方向。
我已经在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方法中也没有。
谁能帮帮我吗?我做错了什么?
任何帮助将不胜感激。
最佳答案
shouldAutorotateToInterfaceOrientation:
是您必须在视图控制器中而不是应用程序委托中实现的方法。为了旋转标签栏应用,标签栏控制器的所有子控制器都必须返回YES
以获得所请求的界面方向。
同样,willRotateToInterfaceOrientation:
和didRotateFromInterfaceOrientation:
将在视图控制器中实现,而不是像您所说的那样在视图中实现。