gpt4 book ai didi

ios - AVCapturePhotoOutput isFlashScene 键值观察

转载 作者:可可西里 更新时间:2023-11-01 00:41:28 25 4
gpt4 key购买 nike

我正在关注 Apple 的最新示例代码 AVCam Swift,该代码已更新为使用 AVCapture Photo Output

var isFlashScene: Bool { get }

A Boolean value indicating whether the scene currently being previewed by the camera warrants use of the flash. This property’s value changes depending on the scene currently visible to the camera. For example, you might use this property to highlight the flash control in your app’s camera UI, indicating to the user that the scene is dark enough that enabling the flash might be desirable. If the photo capture output’s supportedFlashModes value is off, this property’s value is always false. This property supports Key-value observing.

我正在尝试通过键值对观察这一点,以便当自动闪光模式指示这是闪光灯将触发的场景时(就像普通的 iOS 相机应用程序一样),所以我可以更改 UI,就像文档说明一样。

所以我这样设置:

private let photoOutput = AVCapturePhotoOutput()

private var FlashSceneContext = 0

self.addObserver(self, forKeyPath: "photoOutput.isFlashScene", options: .new, context: &FlashSceneContext)

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if context == & FlashSceneContext {
print ("Flash Scene Changed")
}
}

上面从不显示变化。就算我放个登录去查

print (self.photoOutput.isFlashScene)

尽管在应用程序中,这始终显示为 False。

我也试过:

self.photoOutput.addObserver(self, forKeyPath: "isFlashScene", options: .new, context: &FlashSceneContext)

.... Flash Scene 仍然没有变化,它停留在 False 上。

最佳答案

self.photoOutput.addObserver(self, forKeyPath: "isFlashScene", options: .new, context: &FlashSceneContext)

以上是设置 KVO 的正确方法。

必须实现 photoSettingsForSceneMonitoring:

let photoSettings = AVCapturePhotoSettings()
photoSettings.flashMode = .auto
photoSettings.isAutoStillImageStabilizationEnabled = true
self.photoOutput.photoSettingsForSceneMonitoring = photoSettings

有效!

关于ios - AVCapturePhotoOutput isFlashScene 键值观察,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43147577/

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