启动模式视图控制器来解决标签栏和导航VC的方向“locking”?
我有一个iPhone应用程序与根视图控制器(VC)的UITabBarController(设置为纵向)与几个选项卡,其中之一是一个简单的UIViewController。 在这个UIViewController是一个单一的button – “播放video”,当点击打开video模式视图(并自动开始播放video)。 video视图是UIViewController中的一个UIWebView。 我一直在试图让Web视图的VC改变方向为风景,但没有任何运气。
我环顾四周,明白如果你有一个标签栏或一个导航控制器,所有儿童风险投资将与父母一样的方向 – 是有道理的。 这就是为什么我做了networking视图的VC模式,希望这是一个方向问题的方式。
我的问题是:这是否准确 – 使用模态不需要Web视图VC是肖像,并可以响应shouldAutorotateToInterfaceOrientation方法(即使我还没有能够得到它的工作)?
顺便说一下,使用iOS 6。
提前致谢。
显然在iOS6及以上版本中,旋转的方式是不同的。 所以你要做的是以下几点
- 在您的.plist支持所有4个方向。
- 子类UITabBarController(例如:CustomTabBarController)
-
在CustomTabBarController中放入以下几行代码
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
-
在您的应用程序委托或您正在初始化UITabBarController的位置,将这些实例replace为CustomTabBarController实例。
-
在你的模态控制器把行
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeLeft; } -(BOOL)shouldAutorotate{ return NO; }
它应该都可以工作。
显然这个技巧,我发现,UITabBarController不会听你的指示。 它将支持您在.plist中提到的所有方向。
因此,您必须将其子类化。
我试着做所有上述,它工作正常。 请让我知道,如果你愿意,我可以给你发送代码。
尝试这个。 只需在摘要屏幕中设置肖像,然后在应用程序委托中执行此操作:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; }
在标签栏控制器(并没有其他的旋转代码):
-(BOOL)shouldAutorotate { return NO; }
最后,在模态视图控制器中:
-(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; }