如何检测AVPlayerViewController的全屏模式

sve*_*rin 10 avfoundation ios8

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

kam*_*ala 5

也可以观察到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");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Chr*_*isH 4

您可以使用 KVO 来观察实例videoBounds的属性AVPlayerViewController

编辑 最基本的例子是

[_myPlayerViewController addObserver:self forKeyPath:@"videoBounds" options:0 context:nil];
Run Code Online (Sandbox Code Playgroud)