我有两个视图控制器。一个视图有按钮,当用户点击按钮时,他将重定向到另一个存在MPMoviePlayer控制器的视图。我想默认显示MPMoviePlayer控制器视图到LandsapeRight模式。
我在buttonAction中编写了以下代码
-(void)buttonAction
{
tLive = [[toneTvlive alloc]init];
[self.navigationController pushViewController:tLive animated:YES];
}
在第二个视图中我写下面的代码
- (void)viewDidLoad
{
[super viewDidLoad];
printf("\n hii");
self.navigationController.navigationBar.hidden = YES;
[[UIApplication sharedApplication]setStatusBarHidden:NO];
NSURL *mediaURL = [NSURL URLWithString:@""];
mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
//[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES animated:YES];
[mp.view setFrame: CGRectMake(0,0, 480,320)];
[self.view addSubview:mp.view];
[mp prepareToPlay];
[mp play];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
首先运行程序时它只显示纵向模式的视图。它不会提示视图在横向旋转,但是当我旋转设备后它工作正常。任何人都可以帮我解决这个问题。
答案 0 :(得分:0)
如果您使用的是iOS 6+,则可以将视图控制器自动旋转到横向:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return YES;
}
如果你的目标是早期的iOS版本,那么a good SO answer也是如此。