我在ViewController中添加了这段代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if (interfaceOrientation != UIInterfaceOrientationPortrait) {
[self.moviePlayerController setFullscreen:YES animated:YES];
}
return YES;
}
所以旋转后我的播放器以全屏模式播放视频。我需要在playerController(OrientationPortrait)中捕获旋转事件to setFullScreen:NO。 我怎样才能做到这一点? 谢谢你的回答。
答案 0 :(得分:3)
不应在此功能中处理moviePlayerController的方向设置。
在viewWillAppear函数中添加通知程序
-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];}
方向更改通知此功能
- (void)orientationChanged:(NSNotification *)notification{
[self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}
进而调用此函数处理moviePlayerController框架的方向
- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
[self.moviePlayerController setFullscreen:NO animated:YES];
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
[self.moviePlayerController setFullscreen:YES animated:YES];
}}
在viewDidDisappear中删除通知
-(void)viewDidDisappear:(BOOL)animated{
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];}