2

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

我想也许是,不应该去风景的意见,可能有办法: 防止视图改变例如,每当设备变为风景 或 时调用setOrientation:UIDeviceOrientationPortrait给出视图不会改变的错觉,例如,在旋转的视图上呈现模态肖像视图

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

回答

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; 
    } 
} 

我希望我能帮助当前方向一点点。

+0

哦,不要忘记删除通知处理程序,如果视图中消失... \t [NSNotificationCenter defaultCenter] removeObserver:自 \t \t \t \t \t \t \t \t \t \t \t \t \t名:@ “UIDeviceOrientationDidChangeNotification” \t \t \t \t \t \t \t \t \t \t \t \t object:nil]; – samsam 2010-05-06 07:29:31

+0

我只是想检查一下,我明白了,我会留下所有其他的意见,因为不支持风景&然后你的代码将确保方向改变消息仍然可以收到的旋转视图控制器,我是否正确? – 2010-05-06 07:54:04

+0

是的,这是正确的。我有同样的问题:5个纵向视图(每个都是一个NavigationController的“根视图”并且连接到TabBar)...除了应该改变旋转角度的那个外,你可以保留所有这些视图。我实现了一个Cover-Flow-View,在更改设备旋转时显示,它工作得很好。 – samsam 2010-05-06 09:46:34

相关问题