限制包含UINavigationController的UITabBarController中的横向视图

时间:2010-05-06 07:15:18

标签: uinavigationcontroller uitabbarcontroller limit landscape

我有一个标签栏应用程序,其中包含2个选项卡中的导航视图。我想1导航控制器中的1个视图允许横向视图,但由于标签栏限制中的导航栏我现在必须允许我的应用程序中的每个视图的横向视图,以使倾斜消息传递到我的应用程序,我不想要。

我想也许,在不应该去景观的观点上,可能有办法:  防止视图改变,例如每当设备走向风景时调用setOrientation:UIDeviceOrientationPortrait 要么  给人一种观点不会改变的错觉,例如:在旋转视图上显示模态纵向视图

任何人都有任何想要分享的想法或经验吗?这里最好的方法是什么? (我现在不想为每个视图设计横向视图,以便我可以为1个视图显示纵向和横向视图)

1 个答案:

答案 0 :(得分:2)

我最近不得不处理同样的问题,我的解决方案如下:

在视图的UIViewController中您希望能够旋转UIDeviceOrientationDidChangeNotification添加通知处理程序

-(void)viewDidLoad {


[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didRotateFromInterfaceOrientation)
                                             name:@"UIDeviceOrientationDidChangeNotification" object:nil];

}

当然,您需要实施didRotateFromInterfaceOrientation方法。

在该方法中,您可以使用

获取当前方向
 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

我接下来要做的是根据方向评估我想要显示的视图

switch (orientation) {
    case UIDeviceOrientationLandscapeLeft:
        NSLog(@"UIDeviceOrientationLandscapeLeft");
        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationLandscapeRight:
        NSLog(@"UIDeviceOrientationLandscapeRight");

        [self presentModalViewController:LandscapeView animated:YES];

        break;
    case UIDeviceOrientationPortraitUpsideDown:
        NSLog(@"UIDeviceOrientationPortraitUpsideDown");
        [LandScapeview dismissModalViewControllerAnimated:YES];

        break;
    case UIDeviceOrientationPortrait:
        NSLog(@"UIDeviceOrientationPortrait");
        [LandscapeView dismissModalViewControllerAnimated:YES];
        break;

    case UIDeviceOrientationFaceUp:
        NSLog(@"UIDeviceOrientationFaceUp");

        break;

    case UIDeviceOrientationFaceDown:
        NSLog(@"UIDeviceOrientationFaceDown");
        break;

    default:
        break;
    }
}

我希望我能帮上忙。

相关问题