1

视频按钮位于导航栏的 ViewController 中,按下该按钮后,它将立即以纵向模式显示视频。如果我手动旋转它,它只会在风景中。如何在按下按钮后立即以横向模式观看视频?我需要 ViewController 处于纵向模式,只有视频处于横向模式。

这是 ViewController.m 文件:

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

-(IBAction)backbutton
{
    ChapterTableViewController *chapterTable = [self.storyboard instantiateViewControllerWithIdentifier:@"chapterTable"];

    [self.navigationController presentModalViewController:chapterTable animated:YES];
}

-(IBAction)playvideo
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                        pathForResource:@"One Piece Episode 180" ofType:@"mp4"]];

    MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

    [self presentMoviePlayerViewControllerAnimated:playercontroller];
    playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [playercontroller.moviePlayer play];
    playercontroller = nil;
} 

@end
4

3 回答 3

0
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

[[self view] setBounds:CGRectMake(0, 0, 480, 320)];
[[self view] setCenter:CGPointMake(160, 240)];
[[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

对于全屏播放,请使用 MPMoviePlayerViewController,然后使用 MPMoviePlayerViewController 类上的“shouldAutorotateToInterfaceOrientation”方法使其以横向格式启动和播放。

它看起来像这样:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];
于 2012-07-10T04:39:20.937 回答
0

请尝试这个 ViewController.m 以及这个 ViewController 被推送的视图

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
于 2012-07-10T05:50:54.313 回答
-1

您可以选择他想在 ViewController 文件中以哪种模式录制视频的用户天气,然后您可以检查视频控制器中的以下情况,这样您就可以解决您的问题。这对我有用。

- (int)deviceOrientationDidChange
{   
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    int val;
    if (deviceOrientation == UIDeviceOrientationPortrait){
        orientation = AVCaptureVideoOrientationPortrait;
        val=1;
        NSLog(@"AVCaptureVideoOrientationPortrait");
    }
    else if (deviceOrientation == UIDeviceOrientationPortraitUpsideDown){
        orientation = AVCaptureVideoOrientationPortraitUpsideDown;
        val=2;
        NSLog(@"AVCaptureVideoOrientationPortraitUpsideDown");
    }

    // AVCapture and UIDevice have opposite meanings for landscape left and right (AVCapture orientation is the same as UIInterfaceOrientation)
    else if (deviceOrientation == UIDeviceOrientationLandscapeLeft){
        orientation = AVCaptureVideoOrientationLandscapeRight;
        val=3;
        NSLog(@"AVCaptureVideoOrientationLandscapeRight");

    }
    else if (deviceOrientation == UIDeviceOrientationLandscapeRight){
        orientation = AVCaptureVideoOrientationLandscapeLeft;
        val=4;
        NSLog(@"AVCaptureVideoOrientationLandscapeLeft");

    }
    return val;
    // Ignore device orientations for which there is no corresponding still image orientation (e.g. UIDeviceOrientationFaceUp)
}
于 2012-07-10T08:32:25.657 回答