我的应用程序仅是纵向的,但我希望允许用户在通过 UIWebview 观看全屏视频时旋转到横向。我做了一些研究,发现我应该将我的班级添加为这些通知的观察者:
UIMoviePlayerControllerDidEnterFullscreenNotification UIMoviePlayerControllerWillExitFullscreenNotification
我像这样以观察者的身份添加和删除该类:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerDidEnterFullScreen:) name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullScreen:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}
- (void)moviePlayerDidEnterFullScreen:(NSNotification *)notification
{
self.videoPlayingFullScreen = YES;
}
- (void)moviePlayerWillExitFullScreen:(NSNotification *)notification
{
self.videoPlayingFullScreen = NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.videoPlayingFullScreen)
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
我的问题是:我从未收到“UIMoviePlayerControllerWillExitFullscreenNotification”。我不能使用 UIMoviePlayerControllerDidExitFullscreenNotification,因为如果用户在横向观看全屏视频并按下“完成”,则前一个视图控制器也会以横向显示,而它应该是纵向的。
是否有另一种方法来检测用户何时“确实”进入全屏并“将”退出全屏?或者有什么我想念的吗?
编辑: 我的应用程序仅适用于 iOS 7。