2012-07-10 44 views
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 

回答

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,然后让它启动,并以横向格式播放使用“shouldAutorotateToInterfaceOrientation”方法对MPMoviePlayerViewController类。

它看起来像这样:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]; 
+0

我试过使用方法,但它不工作。 – icee 2012-07-10 05:50:08

+0

查看编辑答案 – 2012-07-10 06:17:46

+0

它会变成横向模式,但视频仍处于纵向模式。 – icee 2012-07-10 06:30:06

0

请尝试一下本作ViewController.m并在此的ViewController被推

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

我需要ViewController处于纵向模式,只有视频处于横向模式。 – icee 2012-07-10 05:57:23

+0

没有让你ViewController是通过你录制视频相同的屏幕? – mshau 2012-07-10 06:48:28

+0

ViewController有一个按钮,在我按下之后,它会转到视频。 – icee 2012-07-10 06:59:37

-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) 
} 
相关问题