申请不会改变方向

Cor*_*lio 2 iphone objective-c orientation screen-orientation

我有一个带有tabbar的应用程序,我想在其中检测界面方向.

我在info.plist中设置了支持的方向.这是我的主要接口声明:

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
   ...
}
Run Code Online (Sandbox Code Playgroud)

这是在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;
    }
Run Code Online (Sandbox Code Playgroud)

在我试图检测方向变化的必要视图中,我称之为以下方法:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
Run Code Online (Sandbox Code Playgroud)

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
Run Code Online (Sandbox Code Playgroud)

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

谁能帮帮我吗?我做错了什么?任何帮助将不胜感激.

Ole*_*ann 5

shouldAutorotateToInterfaceOrientation:是一种必须在视图控制器中实现的方法,而不是在应用程序委托中实现的方法.要使标签栏应用程序旋转,标签栏控制器的所有子控制器都必须返回YES所请求的界面方向.

同样地,willRotateToInterfaceOrientation:并且didRotateFromInterfaceOrientation:将在视图控制器中实现,而不是像您所说的那样在视图中实现.