使用UITabBar在iOS 6中自动旋转单个UIViewController

Pie*_*ero 25 iphone uiviewcontroller landscape-portrait ios6

我有一个只能使用的应用程序Portrait Mode,但是有一个可以显示视频的单一视图,所以我希望该视图也可以工作landscape mode,但是在iOS 6中我无法弄清楚我是如何做到的,现在我有了这个:

在AppDelegate.mi中有:

self.window.rootViewController = myTabBar;
Run Code Online (Sandbox Code Playgroud)

然后在项目摘要中:

在此输入图像描述

我发现在iOS 6中检测视图旋转我必须这样做:

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return YES;
}
Run Code Online (Sandbox Code Playgroud)

所以我只在我的插入代码UIViewController我想在景观中使用,但不工作,谁知道我怎么能这样做?我只是想在显示视频时自动旋转.

mie*_*tus 49

首先,您的目标设置应如下所示: 支持的接口方向

在UITabBarController中:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

-(NSUInteger)supportedInterfaceOrientations
{
    if (self.selectedViewController) 
        return [self.selectedViewController supportedInterfaceOrientations];

    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

在ViewController中:

a)如果你不想轮换:

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

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)

b)如果要旋转到横向:

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

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)

编辑:

其他解决方案是在AppDelegate中实现此方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskAll;

    if (self.window.rootViewController) {
        UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presented supportedInterfaceOrientations];
    }
    return orientations; 
}
Run Code Online (Sandbox Code Playgroud)