You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS 16中exitFullScreenAnimated失效:AVPlayerViewController代理未触发求助

问题分析与解决方案

核心原因

你调用的exitFullScreenAnimated:completionHandler:是AVPlayerViewController的私有未公开方法,苹果在iOS 16及后续版本中对该方法的实现进行了修改或限制了调用权限,导致选择器无法正常执行,进而触发全屏状态变更的代理方法也无法被系统调用。私有API没有官方兼容性承诺,跨版本使用必然会出现这类问题。

官方替代方案

针对iOS版本差异,使用苹果官方提供的API实现退出全屏需求:

  • iOS 16.0及以上:直接调用AVPlayerViewController的官方方法exitFullScreen(animated:)
  • iOS 15及以下:可继续保留原私有方法调用(但需注意后续版本仍存在失效风险)

兼容代码示例:

if #available(iOS 16.0, *) {
    videoViewController.exitFullScreen(animated: animated)
} else {
    videoViewController.perform(NSSelectorFromString("exitFullScreenAnimated:completionHandler:"), with: animated, with: nil)
}

代理方法恢复触发说明

使用官方API后,系统会正确处理全屏状态的变更流程,对应的playerViewController(_ playerViewController: AVPlayerViewController, willExitFullScreenWith coordinator: AVPlayerViewControllerTransitionCoordinator)或playerViewController(_ playerViewController: AVPlayerViewController, didExitFullScreenWith coordinator: AVPlayerViewControllerTransitionCoordinator)代理方法会正常被调用,符合预期逻辑。

内容的提问来源于stack exchange,提问作者William

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 17:30:01