我正在使用 UIImagePickerController 来呈现相机并最初将闪光灯模式设置为自动。
videoCapturer.sourceType = UIImagePickerControllerSourceType.Camera
videoCapturer.mediaTypes = [kUTTypeMovie as String]
videoCapturer.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Auto
[self .presentViewController(videoCapturer, animated: true, completion: nil)]
我想在闪光灯根据光线设置为打开或关闭时收到通知。
最佳答案
只需使用 KVO。
let capture = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
capture.addObserver(self, forKeyPath: "torchActive", options: NSKeyValueObservingOptions.New.union(.Initial), context: nil)
并实现这个方法:
public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if keyPath == "torchActive" {
// do something when torchActive changed
} else {
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}
这是 Apple 对 torchActive 的描述:
@property torchActive
@abstract
Indicates whether the receiver's torch is currently active.
@discussion
The value of this property is a BOOL indicating whether the receiver's torch is
currently active. If the current torchMode is AVCaptureTorchModeAuto and isTorchActive
is YES, the torch will illuminate once a recording starts (see AVCaptureOutput.h
-startRecordingToOutputFileURL:recordingDelegate:). This property is key-value observable.
关于ios - 由于光线不足,如何在自动闪光模式下打开或关闭闪光灯时收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38605746/