2012-07-10 1 views
1

비디오 버튼은 내비게이션 막대의 ViewController에 있으며 눌렀을 때 비디오가 세로 모드로 즉시 표시됩니다. 수동으로 회전하는 경우에만 가로 방향으로 표시됩니다. 버튼을 누른 후 즉시 비디오를 가로 모드로 표시하려면 어떻게합니까? ViewController를 세로 모드로, 가로 모드로만 비디오가 있어야합니다.가로로 비디오를 자동으로 회전하는 방법은 무엇입니까?

- (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를 사용하여 전체 화면 재생 :

이것은 ViewController.m 파일입니다.

그것은 다음과 같습니다

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]; 
+0

나는 방법을 사용하여 시도했지만 작동하지 않습니다. – icee

+0

편집 된 답변 –

+0

가로 모드가되지만 비디오는 세로 모드입니다. – icee

0

이의 ViewController가

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

ViewController를 세로 모드로 설정하고 가로 모드로 설정해야합니다. – icee

+0

ViewController는 비디오를 녹화하는 화면과 동일한 화면입니까? – mshau

+0

ViewController에는 눌린 후 비디오로 이동하는 버튼이 있습니다. – icee

-1

당신은 사용자 날씨 옵션을 제공 할 수 있습니다 밀어되고 있음보기 throuth도 ViewController.m에 대해이 작업을 시도하십시오 그가 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) 
} 
관련 문제