【问题标题】:How to rotate MPMoviePlayerController video but not for its superview如何旋转 MPMoviePlayerController 视频,但不能旋转它的超级视图
【发布时间】:2011-08-02 07:46:45
【问题描述】:

我的 MPMoviePlayerController 视图作为子视图添加到另一个视图控制器的视图中。当我全屏播放视频并翻转模拟器时,视频不翻转,父视图也不翻转。但是,当我在旋转方法中添加return YES 时(检查下面的代码),视频在全屏时旋转,但父视图也会旋转,这是我不想要的,因为我没有设计父视图的横向视图。当视频全屏而不是父视图时,如何仅允许视频旋转??

这是我使用的代码:

对于视频:

- (void)viewDidAppear:(BOOL)animated {

    NSBundle *bundle=[NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"MainPageMovie" ofType:@"mp4"];
    NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    theMovie.view.frame = CGRectMake(115.0, 156.0, 200.0, 150.0);
    [self.view addSubview:theMovie.view];
    [theMovie play];

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}

对于旋转方法:

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

【问题讨论】:

    标签: iphone xcode ios4 video


    【解决方案1】:

    一个简单的方法是使用 MPMoviePlayerViewController 来显示电影。作为一个单独的视图控制器,它应该为你处理旋转。

    如果您真的想通过添加 MPMoviePlayerController 作为子视图来实现,那么您将面临更艰巨的任务。基本上,您必须侦听 UIDeviceOrientationDidChangeNotification 并根据设备的方向将适当的 transformboundscenter 应用于电影播放器​​视图。

    【讨论】:

    • 所以基本上要么我为父视图设计一个横向视图,这将使我为整个应用程序设计横向视图,或者保持视频以纵向视图播放,嗯? :P 无论如何谢谢 :) 我会尝试将视频添加到单独的视图中。这应该可以解决我的问题:)
    猜你喜欢
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多