自动旋转、UIWebView 和 UITabBarController

发布于 2024-10-22 00:59:07 字数 931 浏览 2 评论 0原文

我有以下视图层次结构:

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 仅支持纵向(我对此进行了测试)。当我为父视图控制器启用横向时,它可以工作,但在这种情况下,我遇到用户切换选项卡同时仍处于横向模式的问题(另请参阅我昨天发布的这个问题:更改选项卡时忽略自动旋转

有人知道如何解决此问题吗?一方面,我想让用户能够旋转视频,但另一方面,重写所有其他视图控制器以支持横向似乎需要付出太多努力才能获得优势。

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)

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舂唻埖巳落 2024-10-29 00:59:07

考虑一种不同的方法:不要在整个选项卡控制器层次结构中将包含电影的 UIWebView 呈现为 UIViewController,这会让您陷入整个旋转问题,而是尝试用完全不同的 UIViewController 替换您的顶级视图控制器(UITabBarController) (包含 UIWebView)。

当您想要退出全屏电影模式时,请再次将 UITabBarController 恢复为顶级视图控制器。注意,当您进行切换时,不要忘记删除“旧”视图控制器——当 UIWindow 有多个子视图时,它会变得非常不高兴,并且不会发送自动旋转消息等。

我'我们见过应用程序在面临此类自动旋转障碍时使用类似的策略。

这个策略可能看起来有点“脱节”,你可能需要在切换的更精细方面做一些调整,但它值得一看。

Consider a different approach: rather than presenting your UIWebView with the movie in it as yet an UIViewController in your whole tab controller heirarchy, which ties you into the whole rotation problem, try replacing your top level view controller (UITabBarController) with a totally different UIViewController (containing the UIWebView).

When you want to exit the fullscreen movie mode, reinstate the UITabBarController as the top level view controller again. N.B. do not forget to remove the 'old' view controller when you do a switch -- UIWindow gets very unhappy when it has multiple child views, and autorotation messages don't get sent, etc.

I've seen apps use strategies like this when faced with such autorotation hurdles.

This strategy might seem a bit 'unglued', and you might have to do a little fiddling around the finer aspects of the switching, but it's worth a look.

二手情话 2024-10-29 00:59:07

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

在我的应用程序中,我在需要自动旋转的网络视图中使用这种方法,但在其他视图控制器中则不需要。

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

    [super viewWillAppear:animated];

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

}

  • (void)viewWillDisappear:(BOOL)动画{
    [超级viewWillDisappear:动画];

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

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.

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)animated{

    [super viewWillAppear:animated];

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

}

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文