AVPlayer在全屏热点时调整窗口大小时会崩溃

我正在编写一个应用程序,使用它可以观看各种各样的video。 我在全屏button上点击打开video,用户可以使用播放控件调整窗口大小。 我遇到的问题是,当用户通过热点分享他的互联网时,应用程序顶部有一个蓝色栏。 在此时调整窗口大小会导致AVKit框架崩溃(我相信)。 使用Swift 2.3,Xcode 7.3.1。 我的手机,iPhone 6s,使用iOS 10,我也尝试了iOS 9 iPhone 6 Plus,同样的问题。

碰撞:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<AVFullScreenPlaybackControlsViewController: 0x102933000> should have parent view controller:<AVPlayerViewController: 0x10212d800> but actual parent is:<AVFullScreenViewController: 0x10884d900>' 

我的代码:

 private let playerController = AVPlayerViewController() private var player: AVPlayer! private func playVideo(media: Media) { player = AVPlayer(URL: NSURL(string: media.url)!) playerController.player = player presentViewController(playerController, animated: true, completion: { self.playerController.player?.play() self.playerController.delegate = self }) } 

如果我不在我的手机上共享我的networking(因此没有蓝条),那么它工作正常,没有任何问题。 任何人设法隐藏这个蓝色的酒吧,或经历了类似的问题?

我已经修复了这个代码:

 @interface YourAVPlayerViewController : AVPlayerViewController @end @implementation YourAVPlayerViewController - (BOOL)prefersStatusBarHidden { return YES; } @end 

作为一种解决方法,您可以在navigationControlelr堆栈上进行推送,或者在以模态方式使用这个堆栈时:

 @interface AVPlayerViewController () - (void)fullScreenButtonTapped:(id)arg1; @end @interface RCKPlayerViewController () @end @implementation RCKPlayerViewController - (void)fullScreenButtonTapped:(id)arg1 { if ([[UIApplication sharedApplication] statusBarFrame].size.height >= 40) { // Show alert that cannot enter full screen when in-call } else { [super fullScreenButtonTapped:arg1]; } } @end 

然后,只需使用RCKPlayerViewController

 AVPlayerViewController *playerViewController = [[RCKPlayerViewController alloc] init]; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:videoStringURL]]; AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem]; playerViewController.player = player; [self presentViewController:playerViewController animated:YES completion:^{ [player play]; }];