我正在开发需要播放YouTube视频的iPhone应用程序。以横向方式在UIWebView中播放YouTube视频,而ViewController处于纵向方向
我有一个ViewController在肖像取向只有一个UIWebView加载YouTube视频。
我想要做的是该视频可以横向播放。
这听起来很简单,但我不知道该怎么做。有人可以帮我吗?
谢谢!
我正在开发需要播放YouTube视频的iPhone应用程序。以横向方式在UIWebView中播放YouTube视频,而ViewController处于纵向方向
我有一个ViewController在肖像取向只有一个UIWebView加载YouTube视频。
我想要做的是该视频可以横向播放。
这听起来很简单,但我不知道该怎么做。有人可以帮我吗?
谢谢!
目前没有办法以编程方式开始播放YouTube视频。这就是说,你可以在ViewController的willRotateToInterfaceOrientation:duration中创建一个UIWebview:检查水平方向,并用显示视频缩略图的代码显示webview。但用户仍然必须激活视图。 要删除视频,请使用相同的方法进行,但要使用纵向方向并移除网页视图。
我找到了答案。
1)I将此代码添加到我的viewController.m
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
2)在界面生成器我建立我在景观接口,具有旋转90°的每个单独的元件。
当我建立并运行时,当它实际上是风景时,视图似乎处于纵向模式。因此,嵌入在UIWebView中的YouTube视频将在横向中播放。
这发生在AppDelegate中。将只启用视频播放器的水平模式
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let presentedViewController = window?.rootViewController?.presentedViewController {
let className = String(describing: type(of: presentedViewController))
if ["MPInlineVideoFullscreenViewController", "MPMoviePlayerViewController", "AVFullScreenViewController"].contains(className)
{
return UIInterfaceOrientationMask.allButUpsideDown
}
}
return UIInterfaceOrientationMask.portrait
}