如何呈现视频并仅旋转它?

时间:2013-01-08 23:27:36

标签: iphone ios ipad video mpmovieplayercontroller

我想要做的很简单。

我有UIViewController(仅限肖像!),在其视图中我想要显示视频(在视图的一部分中)。然后我想添加一个UIButton,使用户能够全屏显示视频。 当视频处于全屏状态时,我希望视频遵循设备的方向,而不是UIViewController呈现视频,以便如果用户处于横向状态并退出全屏模式,UIViewController应该在肖像! 我还想在视频全屏时添加自定义控件。

你知道我该怎么办吗?

由于

1 个答案:

答案 0 :(得分:0)

我以前做过这个。只需setTransform:CGAffineTransformMakeRotation(M_PI/2)

- (void)rotateVideoToLandscape {

    int64_t delayInSeconds = 0.5;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
    });

    // Before rotate the video, exchange the width & height for a better user-experience.
    [self.view setBounds:CGRectMake(0, 0, self.view.height, self.view.width)];
    [self.view setCenter:CGPointMake(self.view.width/2, self.view.height/2)];
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];

    CGRect playerRect = self.view.bounds;
    // Do something needed.
    self.moviePlayerController.view.frame = playerRect;
}