有人会如何观察 AVPlayerLayer 的 videoRect 变化?

How would someone observe AVPlayerLayer's videoRect changing?

Apple 文档指出 videoRect 响应 KVO,但我不知道如何实现它:https://developer.apple.com/documentation/avfoundation/avplayerlayer/1385745-videorect

我有一个 playerLayer,但如何为 videoRect 添加观察者?

playerLayer = AVPlayerLayer(player: player!)

self.playerLayer?.videoRect.addObserver(self, forKeyPath:"test", options: [.old, .new], context: nil)

我的问题是我正在尝试对齐依赖于 videoRect 的图像,但 videoRect 在 vi​​ewDidLoad 中设置为全 0。片刻之后,它发生了变化,所以我需要观察它何时发生变化。

您观察到 playerLayer,而不是 videoRect"videoRect" 是关键路径。