从 HTML5
由于某些原因,我的应用程序仅支持纵向。
但是,在某些情况下,我需要显示来自 UIWebView 的视频(带有 video
标签),如果用户可以纵向或横向查看它,那就太好了。
控制器的配置如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
结果:视频仅以纵向模式播放(好吧,完全符合预期)。
我尝试过:
- 设置此项以支持用户启动视频时的所有方向
- 当视频停止时,返回“仅纵向”
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
// autorotationEnabled is toggled when a video is played / stopped
return autorotationEnabled ? YES : UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
结果:横向模式可用(太棒了!),但如果用户在横向播放时点击“完成”,则之前的视图将以横向模式显示一旦球员被解雇(不太好)。
有人知道如何在玩家被解雇时防止控制器以横向模式显示吗?
(不能使用 UIDevice 的私有方法 setInterfaceOrientation )
My app, for some reasons, only supports portrait orientation.
However, in some cases I need to display videos from a UIWebView (with video
tag) and it would be nice if the user can view it either in portrait or landscape.
The controller is configured like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Result: the video is played only in portrait mode (ok, quite expected).
I tried:
- setting this to support all orientations when the user starts a video
- when the video stops, back to "portrait only"
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
// autorotationEnabled is toggled when a video is played / stopped
return autorotationEnabled ? YES : UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}
Result: landscape mode is available (great!) but if the user taps 'Done' while playing in landscape, the previous view will appear in landscape mode once the player is dismissed (not so great).
Does anybody have an idea on how to prevent the controller from being displayed in landscape mode when the player is dismissed?
(using the private method setInterfaceOrientation of UIDevice is not an option)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也做过类似的事情。您必须修改 UIView 堆栈,以强制应用程序在弹出控制器时调用 shouldAutorotateToInterfaceOrientation。
在您的 WebViewController 中设置为允许自动旋转:
在父控制器中不允许自动旋转:
创建并分配 UINavigationControllerDelegate。
在委托中,当控制器弹出或推送时临时修改 UIView 堆栈:
这是一种肮脏的黑客行为,但它确实有效。
I've have done something very similar. You have to modify the UIView stack to force the app to call shouldAutorotateToInterfaceOrientation when you pop the controller.
In your WebViewController set to allow the autorotate:
In the parent controller disallow autorotate:
Create and assign a UINavigationControllerDelegate.
In the delegate, temporarily modify the UIView stack when the controller pops or pushes:
It's kind of a dirty hack, but it works.