ios8 - 如何检测AVPlayerViewController的全屏模式

标签 ios8 avfoundation

如何检测用户何时按下AVPlayerViewController的展开图标?
我想知道正在播放的电影何时进入全屏模式。

最佳答案

还可以观察boundsplayerViewController.contentOverlayView并将其与[UIScreen mainScreen].bounds进行比较,例如:

self.playerViewController = [AVPlayerViewController new];
// do this after adding player VC as a child VC or in completion block of -presentViewController:animated:completion:
[self.playerViewController.contentOverlayView addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];

...

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
    if (object == self.playerViewController.contentOverlayView) {
        if ([keyPath isEqualToString:@"bounds"]) {
            CGRect oldBounds = [change[NSKeyValueChangeOldKey] CGRectValue], newBounds = [change[NSKeyValueChangeNewKey] CGRectValue];
            BOOL wasFullscreen = CGRectEqualToRect(oldBounds, [UIScreen mainScreen].bounds), isFullscreen = CGRectEqualToRect(newBounds, [UIScreen mainScreen].bounds);
            if (isFullscreen && !wasFullscreen) {
                if (CGRectEqualToRect(oldBounds, CGRectMake(0, 0, newBounds.size.height, newBounds.size.width))) {
                    NSLog(@"rotated fullscreen");
                }
                else {
                    NSLog(@"entered fullscreen");
                }
            }
            else if (!isFullscreen && wasFullscreen) {
                NSLog(@"exited fullscreen");
            }
        }
    }
}

关于ios8 - 如何检测AVPlayerViewController的全屏模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26330287/

相关文章:

ios - 使用未声明的标识符 'UIUserNotificationSettings'

swift - 没有自定义单元格的自动单元格高度?

ios - 使用 PHP 在 Objective-C 中上传录制的音频文件

ios - 无法使用 MPMoviePlayerController 从视频中获取多个图像。操作系统状态 -12433

objective-c - AVFoundation 获取歌曲的专辑图片

sorting - 如何在 swift 中使用 "ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering"?

ios - 为什么不调用 UIViewControllerTransitioningDelegate 的 presentationControllerForPresentedViewController 方法?

swift - iOS 键盘只有数字和文本

swift - 从 AVCaptureSession 录制的音频在流式传输到另一台设备时生成 "Bad Address"错误

iphone - 我可以分配由 AVAssetExportSession 导出的 m4a 的采样率或比特率吗