视频按钮位于导航栏的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 :(得分: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];
答案 1 :(得分:0)
请为ViewController.m尝试此操作,并在该视图中尝试使用此ViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
答案 2 :(得分:-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)
}