我想为我的应用中的不同viewControllers设置不同的规则,而不是所有视图中的单个规则(就像你可以在Target-Summary中定义的那样)。
例如我有几个视图我希望我的前几个视图只出现在纵向视图中,但是在我的上一个视图中我希望用户能够在protrait和landscape之间进行切换...我在想我是怎么回事可以这样做。
此外,我已经阅读了用户在横向中导航到视图的问题,并且视图在应该是纵向时显示为横向并且不会改变,直到用户旋转设备,我想尽可能避免这种情况...
所以我的问题是如何根据用户所在的视图允许不同的UIViewController方向。
答案 0 :(得分:1)
这取决于您是以iOS 5还是iOS 6为目标 iOS 5:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
if ((orientation == UIInterfaceOrientationPortrait) ||
(orientation == UIInterfaceOrientationLandscapeLeft))
return YES;
return NO;
}
iOS 6:
在App Summary中设置默认支持的方向,然后在VC中设置您想要的不同:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
此HERE
的Apple文档有关详细信息,请参阅以下问题:
shouldAutorotateToInterfaceOrientation not being called in iOS 6
shouldAutorotateToInterfaceOrientation is not working in iOS 6