自动旋转,UIWebView和UITabBarController [英] Autorotation, UIWebView and UITabBarController

查看:65
本文介绍了自动旋转,UIWebView和UITabBarController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下View层次结构:

I have the following View hierarchy:

UITabBarController
 |
 UINavigationController
 |         |
 |         UIViewController (only supports Portrait rotation)
 |
 UINavigationController
 |         |
 |         UIViewController (only supports Portrait rotation)
 |
 UINavigationController
 |         |
 |         UIViewController (only supports Portrait rotation)
 |         |
 |         UIViewController (has UIWebView with movie in it)
 |
 UINavigationController
           |
           UIViewController (only supports Portrait rotation)

现在的问题是,当我显示其中包含电影的UIWebView并用户按下播放"时,全屏媒体播放器将按预期方式打开.但是,我无法旋转影片,因为父UIViewController仅支持纵向方向(我对此进行了测试).当我为父视图控制器启用横向时,它可以工作,但是在这种情况下,我仍然在横向模式下遇到用户切换选项卡的问题(另请参见我昨天发布的以下问题:

The issue is now that when I display the UIWebView with the movie in it and the user presses "play" the fullscreen media player opens as expected. However, I am not able to rotate the movie since the parent UIViewController only supports Portrait orientation (I tested this). When I enable landscape for the parent view controller it works, yet in this case I run into issues with the user switching tabs whilst still being in landscape mode (see also this question I posted yesterday: Autorotate ignored when changing tabs

有人对此有什么想法吗?一方面,我想赋予用户旋转视频的能力,另一方面,重写其他所有viewController以支持横向效果似乎也需要付出太多努力.

Does anybody have any ideas as to how to go about this? On one hand I want to give the user the ability to rotate the video, yet on the other rewriting all the other viewControllers to support landscape as well seems like too much effort for the advantage.

推荐答案

您可以在视图控制器中发送通知,告诉其他视图控制器需要旋转,以便它们向所有方向返回YES.当您离开视图控制器时,发送另一种不再需要的通知.使用这种方法,您只能在所需的视图中进行自动旋转,并且一旦离开这些视图就可以将其停用.

You can send a notification in viewcontrollers to say other view controllers that rotation is required so that they return YES to all orientations.When you leave the view controllers you send another notifications that it is no longer required.With that approach you could have autorotation only in the views that you want and as soon as you leave these views you deactivate it.

在我的应用中,我正在需要自动旋转的Web视图中使用此方法,而在其他视图控制器中则不需要.

In my app i am using this approach in a web view where auto rotation is required but not in other view controllers.

  • (void)viewWillAppear:(BOOL)动画{

  • (void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated];

[super viewWillAppear:animated];

NSNotification * autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification对象:[NSNumber numberWithBool:YES]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification];

NSNotification *autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification object:[NSNumber numberWithBool:YES]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification];

}

  • (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated];

  • (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated];

NSNotification * autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification对象:[NSNumber numberWithBool:NO]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification]; }

NSNotification *autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification object:[NSNumber numberWithBool:NO]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification]; }

这篇关于自动旋转,UIWebView和UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆