您可以輕鬆地通過使用AVFoundation
框架喜歡訪問它改變設備手電筒模式:
雨燕3.0
func toggleTorchMode() {
if let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo), device.hasTorch {
let isTorchSupported = device.isTorchModeSupported(mode)
let isTourchAvailable = device.isTorchAvailable
if isTorchSupported && isTourchAvailable {
do {
try device.lockForConfiguration()
if device.torchMode == AVCaptureTorchMode.on {
device.torchMode = AVCaptureTorchMode.off
}
else {
device.torchMode = AVCaptureTorchMode.on
}
device.unlockForConfiguration()
} catch {
Globals.printlnDebug("Error in setting the torch mode")
}
}
else if mode == AVCaptureTorchMode.on{
Globals.showErrorMessage("Torch not available", inViewController: self)
}
}
}
目標C
-(void)toggleTorchMode
{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ((device) && (device.hasTorch) && (device.isTorchAvailable)) {
[device lockForConfiguration:nil];
if (device.torchMode == AVCaptureTorchModeOn) {
device.torchMode = AVCaptureTorchModeOff;
}
else {
device.torchMode = AVCaptureTorchModeOn;
}
}
else {
//ERROR: Device doesn't have tourch
}
}
但我使用的UIImagePickerController我想用它不AVFoundation框架 –
實現,我想一個閃光模式不手電筒模式 –
UIImagePickerView打開默認攝像機視圖來捕獲並有默認的控制來管理閃存。 –