因此,我正在創建一個照相機應用程序,並且我想要一個用於開/關/自動的閃光燈按鈕,然後當用戶點擊快門黃油時,閃光燈將熄滅啓用。我爲閃光燈創建了一個按鈕,但我不知道該怎麼做。創建一個按鈕以在拍攝照片時切換閃光燈
@IBAction func didTouchFlashButton(sender: UIButton) {
}
這是我的按鈕,這是我的按鈕拍照
@IBAction func didPressTakePhoto(_ sender: UIButton) {
// UIImagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashMode.On
if let videoConnection = stillImageOutput!.connection(withMediaType: AVMediaTypeVideo) {
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
if (sampleBuffer != nil) {
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
let dataProvider = CGDataProvider(data: imageData as! CFData)
let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent)
let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.right)
self.photos.append(image)
print("Photo saved to array")
print(self.photos)
// UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
})
}
}
所以基本上我想要的按鈕來告訴是否使用閃光燈或不和這取決於用戶決定它會在didPressTakePhoto
https://developer.apple.com/reference/avfoundation/avcapturedevice/1388116-flashmode – matt