MPMoviePlayerViewController方向与设备不同

时间:2014-05-29 18:10:43

标签: ios objective-c orientation

我在pageView.m中创建了一个vimeo播放器:

@interface pageView ()
@property (strong, nonatomic) MPMoviePlayerViewController *playerViewController;
@end

和此:

[YTVimeoExtractor fetchVideoURLFromURL:vimeos
                                   quality:YTVimeoVideoQualityHigh
                         completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
                             if (error) {
                                 // handle error
                                 NSLog(@"Video URL: %@", [videoURL absoluteString]);
                             } else {
                                 // run player
                                 self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
                                 [self.playerViewController.moviePlayer prepareToPlay];
                                 [self presentViewController:self.playerViewController animated:YES completion:nil];
                             }
                         }];

这一切都很好。除了方向只是垂直的事实。我已将设备方向设置为纵向,因为我肯定不想更改它。但我希望能够将playerViewController仅作为横向。这可能吗?


我试过这个

[[self.playerViewController view] setTransform:CGAffineTransformMakeRotation(M_PI_2)];

但是不起作用

1 个答案:

答案 0 :(得分:1)

如果您将其设置为纵向,则可以覆盖supportedInterfaceOrientationsForWindow以仅允许playerViewController的横向显示:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[playerViewController class]])
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}

该代码位于appdelegate