全屏 YouTube 视频、旋转和状态栏 (iOS)
我在当前的项目中遇到了一个问题,因此我开发了一个简单的应用程序来看看是否可以隔离问题。在我的应用程序委托中,我隐藏了状态栏。
[application setStatusBarHidden:YES animated:NO];
在我的单视图控制器中,我有以下代码:
- (void)loadVideo
{
// HTML to embed YouTube video
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, @"http://www.youtube.com/watch?v=VDRoBnL1gRg", 500, 500];
// Load the html into the webview
[self.webview loadHTMLString:html baseURL:nil];
}
该应用程序也设置为自动旋转。
现在,问题来了:当我播放 youtube 视频,进入全屏模式,将设备旋转 90 度,然后点击“完成”退出全屏时,整个界面仍然向下移动 20px,就像容纳状态栏一样。我注意到,当全屏观看视频时,ios 会添加一个状态栏,所以我猜测这是问题的一部分。我也发现本机视频播放器也出现此问题。
有什么想法吗?
I came across an issue in my current project, so I spun up a simple app to see if I could isolate the problem. In my app delegate I hide the status bar.
[application setStatusBarHidden:YES animated:NO];
In my single view controller I have this code:
- (void)loadVideo
{
// HTML to embed YouTube video
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, @"http://www.youtube.com/watch?v=VDRoBnL1gRg", 500, 500];
// Load the html into the webview
[self.webview loadHTMLString:html baseURL:nil];
}
The app is also set to autorotate.
Now, here's the problem: When I play the youtube video, enter fullscreen mode, rotate the device 90 degrees, and hit "Done" to exit fullscreen, the entire interface remains shifted down 20px as if it were accommodating a status bar. I noticed that when viewing a video in full screen, ios adds a status bar, so I'm guessing that's part of the issue. I've seen the problem occur with the native video player as well.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我最近在我的应用程序《游戏指南:黑色行动 2》中使用了这个 YouTube 嵌入方法,当我点击电影播放器的“完成”按钮时,我遇到了这个问题并显示了 rootViewController。检查 rootViewController 上的“想要全屏”修复了 20 像素的偏移,并修复了按下“完成”按钮后显示的 rootViewController,我将其添加到 rootViewController 中,该 rootViewController 添加了一个 UIViewController (带有 tableView)作为使用的子项[presentViewControllerAnimated:(BOOL)completion:nil] 显示带有 YouTube 视频嵌入的 ViewController。
现在一切都运行良好...如果您想了解它的行为方式,请查看我的应用程序中的“视频”选项卡。
ios
youtube iPhone 旋转 状态栏 mpmovieplayerviewcontroller
I used this YouTube embed method recently for my app Game Guide: Black Ops 2, and I was having this problem along with being shown the rootViewController when hitting the movie player's "done" button. Checking "Wants Full Screen" on the rootViewController fixed the 20 pixel shift, and to fix the rootViewController being displayed after pushing the "done" button I added this to the rootViewController which was adding a UIViewController (with tableView) as a child which was using [presentViewControllerAnimated:(BOOL) completion:nil] to show the ViewController with the YouTube Video Embed.
Now everything is working perfectly... check out the Videos tab in my app if you want to see how it behaves.
}
ios youtube iphone rotation statusbar mpmovieplayerviewcontroller
我有类似的问题。
我在故事板中创建了视图。检查视图控制器设置的布局部分中的
想要全屏
为我解决了这个问题。I had a similar problem.
I created views in storyboard. Checking
Wants full Screen
in layout section of view controller settings solved it for me.如果您有机会使用 UITabBarController,则必须将此视图安装为窗口的根目录。与其他视图控制器不同,标签栏界面永远不应该安装为另一个视图控制器的子级。
If by any chance you're using a UITabBarController, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
要尝试添加到您的 info.plist 下一个键:UIStatusBarHidden(“状态栏最初是隐藏的”),值为 YES。
To try to add to your info.plist next key: UIStatusBarHidden ("Status bar is initially hidden") with value YES.