允许一个视图支持多个方向而其他人不要iPhone
我有一个情况,我有多个视图通过UITabBarController
控制。 其中一个视图是通过UINavigationController
控制的。 应用程序应该只支持所有视图的肖像…除了一个单独的视图。 这个视图被推到导航控制器的堆栈上,并且应该允许纵向和横向。
我已经尝试了所有我能想到的解决scheme,但是,解决scheme无法正常工作,或者更糟是完全不可预知的。
有没有人以一种干净的方式解决这个问题?
您使用presentModalViewController
或pushViewController
呈现的视图的控制器应该支持任何方向,使用此方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }
使用这种方法,当您以横向方向呈现控制器时,它也会正确地以横向出现。
我有同样的问题。 你必须实现shouldAutorotateToInterfaceOrientation:
对于你的UITabBarController
并且在所有的视图控制器中你想支持的所有方向返回YES。 而在所有其他视图控制器的相同方法中,只有在每个视图控制器中要支持的方向才会返回YES。
要实现shouldAutorotateToInterfaceOrientation:
对于您的UITabBarController,您可以inheritanceUITabBarController,但更简单的方法是在UITabBarController上实现一个类别,并只实现该方法:
@implementation UITabBarController(orientation) -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation { return YES; // or whatever you need } @end
注意:input网页浏览器; 没有编译。 🙂
你可以把这个权利放在你的应用代理.m文件中。
我发现UITabBarController只为肖像返回YES,这显然也会影响所有从属视图控制器。 在我的情况下,我有一个从属视图控制器,我想支持肖像和风景,这解决了它。
如果你有一个标签栏内的导航,那么唯一的select是将特定的视图呈现为模式视图(标签栏需要所有视图支持自动旋转的方向)。 所以基本上需要景观的单个视图控制器应该实现
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { // Create the landscape version of the view and present it modally } return (interfaceOrientation == UIInterfaceOrientationPortrait); }
然后在模式视图控制器的相同的方法,通过检测纵向方向和使用父母的方法解除模态视图[self.parentViewController dismissModalViewControllerAnimated: animated]
对于iOS-6,我已经做到了这一点,它运行得非常好
(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft; } (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; }
这将帮助你…