防止UIWebView全屏旋转
我有一个 UIWebView 可能会显示 YouTube 视频,因此当它发生时它会全屏显示。我的应用程序不旋转,但 UIWebView 旋转,所以如果我停止以横向模式观看它,当我返回屏幕时它会变得狂暴。
我如何监听用户点击完成或直接避免 UIWebView 旋转?
谢谢!
I have an UIWebView that might show a YouTube video, so when it happens it goes full screen. My app doesn't rotates, but the UIWebView rotates, so if i stop watching it in landscape mode, when i return to my screen it goes berserk.
How can i listen for when the user taps done or to directly avoid the UIWebView to rotate?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
我们经常有仅纵向应用程序,通过网络视图显示横向视频。
您确定从顶部视图控制器的 shouldAutorotateToOrientation: 方法返回横向方向为“否”吗?当你说“发狂”时,你是什么意思?我发现的一件事是,设置主窗口的 rootViewController 属性(而不是仅仅将根视图控制器的视图添加为窗口视图的子视图)在从此类视频返回时可能会导致麻烦。
We regularly have portrait-only apps that show landscape videos via web views.
Are you sure you're returning NO for landscape orientations from your shouldAutorotateToOrientation: method of the top view controller? When you say "goes berserk," what do you mean? One thing I've found is that setting the main window's
rootViewController
property (rather than just adding your root view controller's view as a subview of the window view) can cause trouble when returning from videos like this.我知道我晚了几个月,但我编写了一个简单的
UINavigationController
子类来正确传递shouldAutorotateToInterfaceOrientation
、willRotateToInterfaceOrientation
和 < code>didRotateFromInterfaceOrientation 调用正确的视图控制器。希望这有帮助:)
https://gist.github.com/bbae6291c4f6bf05d1eb
I know I'm a few months late, but I've written a simple
UINavigationController
subclass to properly pass theshouldAutorotateToInterfaceOrientation
,willRotateToInterfaceOrientation
, anddidRotateFromInterfaceOrientation
calls through to the proper view controller.Hope this helps :)
https://gist.github.com/bbae6291c4f6bf05d1eb
当视频从全屏关闭时,将调用
UIViewController
中的viewWillAppear:
方法。您可以通过在UIView
上调用setNeedsDisplay
来调整视图The method
viewWillAppear:
in yourUIViewController
will be called when the video is closed from full screen. You can adjust the view there by callingsetNeedsDisplay
on yourUIView