2013-04-05 50 views
2

我正在製作一個只支持肖像模式的應用程序。我在uiwebview中加載了youtube視頻。所以當我切換到橫向模式時,視頻也必須在橫向模式下播放。但在錄製完錄像機之後。我的視圖控制器改變爲橫向模式,但它是在肖像模式下只有在這裏是我的WebView代碼如何在橫向模式下播放視頻,但應用只支持縱向模式?

  web=[[UIWebView alloc]initWithFrame:CGRectMake(2,0, 140, 99)]; 
      web.backgroundColor=[UIColor redColor]; 
     [web setDataDetectorTypes: UIDataDetectorTypeNone]; 

     NSString *embedHTML = @"<iframe title=\"YouTube video player\" width=\"320\" height=\"460\" scrolling=\"no\" src=\"http://www.youtube.com/embed/%@?modestbranding=1&amp;rel=0;autoplay=1;showinfo=0;loop=1;autohide=1\" frameborder=\"0\" allowfullscreen allowTransparency=\"true\"></iframe>"; 

     NSString *htmlStr = [NSString stringWithFormat:embedHTML, [youtubeId_array objectAtIndex:i]];    
     web.tag=i+100; 
     web.scrollView.bounces=NO; 
     [web loadHTMLString:htmlStr baseURL:nil]; 
     [view addSubview:web]; 

    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    return (toInterfaceOrientation=UIInterfaceOrientationPortrait); 
} 

回答

0

你試過設置rootViewControllerself,當您返回到應用程序?

在你的ViewController:

import "AppDelegate.h" 
... 
- (void)functionRunWhenVideoFinish { 
    ... 
    self.appDelegate.window.rootViewController = self; 
    ... 
} 
+0

對不起,iam不能理解你在說什麼? – user2230971 2013-04-05 09:39:37

+0

當你從youtube返回你的應用程序時,在你的視圖控制器中將被觸發的方法中,嘗試將你的應用程序的根視圖控制器設置爲該視圖控制器。 首先在視圖控制器中導入AppDelegate.h,然後添加一個像這樣的屬性@property(retain,nonatomic)ALCAppDelegate * appDelegate; finally add self.appDelegate.window.rootViewController = self;到你的代碼 – Lucabro 2013-04-05 10:31:43

0

添加在AppDelegate中和您所需的視圖控制器

這些線路的同時單擊完成按鈕的應用程序將需要移動的方向。

-(BOOL)shouldAutorotate 
{ 
    return NO; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    //LandScapeMode:- UIInterfaceOrientationMaskLandscape; 
    //PortraitMode:- 
    return UIInterfaceOrientationMaskPortrait 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    //LandScapeMode:- UIInterfaceOrientationLandscapeRight; 
    // ProtraitMode:- 
    return UIInterfaceOrientationPortrait 
} 
相關問題