如何在横向模式下播放视频,但app仅支持纵向模式?

时间:2013-04-05 09:04:00

标签: ios xcode uiwebview orientation

我正在创建一个仅支持Portrait模式的应用程序。我在uiwebview中加载youtube视频。所以当我切换到横向模式时,视频也必须以横向模式播放。但在录制完videoplayer之后。我的视图控制器正在更改为横向模式,但它只处于纵向模式,这里只是我的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);
}

2 个答案:

答案 0 :(得分:0)

您是否尝试在返回应用时将rootViewController设置为self

在你的viewcontroller中:

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

答案 1 :(得分:0)

在Appdelegate和您的必需视图控制器中添加这些行

点击完成按钮应用程序将移动所需的方向。

-(BOOL)shouldAutorotate
{
    return NO; 
}

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    //LandScapeMode:- UIInterfaceOrientationLandscapeRight;
   // ProtraitMode:-
   return UIInterfaceOrientationPortrait
}