【问题标题】:How to play a video in landscape mode but app support only portrait mode?如何以横向模式播放视频但应用程序仅支持纵向模式?
【发布时间】:2013-03-27 15:04:08
【问题描述】:

我正在制作一个仅支持肖像模式的应用程序。我在 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);
}

【问题讨论】:

    标签: ios xcode uiwebview orientation


    【解决方案1】:

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

    在您的视图控制器中:

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

    【讨论】:

    • 对不起,我听不懂你在说什么?
    • 当您从 youtube 返回您的应用程序时,在您的视图控制器中将被触发的方法中,尝试将您的应用程序的根视图控制器设置为该视图控制器。首先在视图控制器中导入 AppDelegate.h,然后添加这样的属性 @property (retain,nonatomic) ALCAppDelegate *appDelegate;最后添加 self.appDelegate.window.rootViewController = self;到你的代码
    【解决方案2】:

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

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

    -(BOOL)shouldAutorotate
    {
        return NO; 
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        //LandScapeMode:- UIInterfaceOrientationMaskLandscape;
        //PortraitMode:- 
        return UIInterfaceOrientationMaskPortrait 
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        //LandScapeMode:- UIInterfaceOrientationLandscapeRight;
       // ProtraitMode:-
       return UIInterfaceOrientationPortrait
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2016-08-14
      • 1970-01-01
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      相关资源
      最近更新 更多