我的應用只有肖像,但是,我想讓用戶在通過UIWebview觀看全屏視頻時旋轉到風景。我做了一些研究,發現我要補充我的類作爲這些通知觀察員:UIMoviePlayerControllerWillExitFullscreenNotification沒有收到
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。
這些通知沒有記錄,因此在使用時會有超級風險,因爲它們可能會在發佈新操作系統更新時破壞應用程序。例如,UIMoviePlayerControllerDidExitFullscreenNotification永遠不會在iOS6上發送。 – Till
是否有文檔記錄的方式來檢測UIWebview何時進入並將全屏退出? – Jonathan
按照[此答案](http://stackoverflow.com/a/8554077/91282)所述使用JavaScript事件。 – Till