2016-07-27 16 views
1

如何獲得通知正在使用的UIImagePickerController呈現相機,最初使閃光模式爲自動。當Flash ON或OFF自動閃光模式下,由於光線較暗

videoCapturer.sourceType = UIImagePickerControllerSourceType.Camera 
videoCapturer.mediaTypes = [kUTTypeMovie as String] 
videoCapturer.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Auto 
[self .presentViewController(videoCapturer, animated: true, completion: nil)] 

i see a yellow flash icon appear and disappear according to the lighting in the bottom upper to the capture button.

我希望在閃光燈根據照明設置爲ON或OFF得到通知。

回答

1

只需使用志願。

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) 
    } 
} 

這裏是蘋果公司的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. 
+0

時提出UIImagePickerController類這隻叫,不叫當閃光燈模式改變自動由於照明。 – Rajjjjjj

+0

我有更新我的答案,希望這會有所幫助。 – zylenv