iOS最新版本中Better Player的屏幕旋转异常问题
Better Player iOS最新版本旋转后画面回退问题的解决方案
- 确认项目屏幕旋转权限配置:检查
Info.plist里的UISupportedInterfaceOrientations(iPhone)和UISupportedInterfaceOrientations~ipad(iPad),确保包含你需要的所有旋转方向枚举值,比如UIInterfaceOrientationPortrait、UIInterfaceOrientationLandscapeLeft、UIInterfaceOrientationLandscapeRight。 - 核对Better Player初始化配置:初始化
BetterPlayerConfiguration时,确保handleLifecycle设为true,同时将autoDetectFullscreenDeviceOrientation设置为true,这个参数负责自动识别设备旋转来同步全屏状态。 - 手动绑定旋转事件:如果自动检测失效,在ViewController的
viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)方法中,手动调用Better Player的全屏切换方法,同步画面方向:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) coordinator.animate(alongsideTransition: { _ in let isLandscape = size.width > size.height if isLandscape { self.betterPlayerViewController?.enterFullScreen() } else { self.betterPlayerViewController?.exitFullScreen() } }) }
- 监听系统旋转通知强制刷新:添加
UIDevice.orientationDidChangeNotification通知,在回调里触发播放器方向更新:
NotificationCenter.default.addObserver(self, selector: #selector(onOrientationChanged), name: UIDevice.orientationDidChangeNotification, object: nil) @objc private func onOrientationChanged() { betterPlayerView.player?.updateVideoOrientation() }
- 升级Better Player到最新版本:该问题可能是库的版本适配bug,升级到最新版本大概率能解决。
内容的提问来源于stack exchange,提问作者Princh Kumar Verma
相关产品推荐
相关产品推荐

