2011-06-03 91 views

回答

0

目前没有办法以编程方式开始播放YouTube视频。这就是说,你可以在ViewController的willRotateToInterfaceOrientation:duration中创建一个UIWebview:检查水平方向,并用显示视频缩略图的代码显示webview。但用户仍然必须激活视图。 要删除视频,请使用相同的方法进行,但要使用纵向方向并移除网页视图。

0

我找到了答案。

1)I将此代码添加到我的viewController.m

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

2)在界面生成器我建立我在景观接口,具有旋转90°的每个单独的元件。

当我建立并运行时,当它实际上是风景时,视图似乎处于纵向模式。因此,嵌入在UIWebView中的YouTube视频将在横向中播放。

1

这发生在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 
} 
相关问题