2011-06-03 94 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 
} 
相關問題