gpt4 book ai didi

ios - AirPlay 外部屏幕返回 (0, 0, 0, 0) 作为边界

转载 作者:行者123 更新时间:2023-11-30 13:18:39 28 4
gpt4 key购买 nike

我现在正在使用 AirPlay 来显示 AVPlayerLayer。这是我的代码片段:

        let secondScreen = UIScreen.screens()[1]
secondScreen.overscanCompensation = UIScreenOverscanCompensation(rawValue: 3)!
let screenBounds = secondScreen.bounds

self.secondWindow = nil // free window when switching between two AirPlay devices
self.secondWindow = UIWindow.init(frame: screenBounds)
self.secondWindow?.screen = secondScreen

layer.removeFromSuperlayer()
layer.frame = screenBounds
layer.videoGravity = AVLayerVideoGravityResizeAspect
self.externalAirPlayView = nil // free view when switching between two AirPlay devices
self.externalAirPlayView = UIView(frame: screenBounds)
self.externalAirPlayView!.layer.addSublayer(layer)
self.secondWindow?.addSubview(self.externalAirPlayView!)
self.secondWindow?.makeKeyAndVisible()

这段代码通常工作正常,但有时我得到 (0, 0, 0, 0) 作为外部屏幕的边界。我还在 UIScreenDidConnectNotification 中得到 (0, 0, 0, 0) 。在这两种情况下,AVPlayerLayer 不会显示在 AirPlay 设备上,因为窗口框架设置不正确。

请注意,如果我将 (0, 0, 0, 0) 作为边界,即使一次,我将永远不会再次获得正确的边界,直到我重新启动应用程序或重新初始化当前 View Controller 。重新启动 AirPlay 设备似乎没有帮助。

有没有办法获得外部屏幕的正确边界?

最佳答案

好吧,我终于解决了这个问题。您可以在可用模式属性中找到正确的屏幕尺寸。代码看起来像这样

for screenMode in secondScreen.availableModes {
if screenMode.size.width != && screenMode.size.height != 0 {
screenBounds.size = screenMode.size
break
}
}

关于ios - AirPlay 外部屏幕返回 (0, 0, 0, 0) 作为边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37980005/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com