2017-06-21 128 views
-1

工作不閃爍的閃光燈光 -相機閃光燈不能從uiimageviewcontroller IOS

-(void)_flashToggle 
{ 
if (! [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceRear ]) 
    return; 

if (PickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeOff) 
    PickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; 
else 
    PickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; 
} 

回答

0

您可以輕鬆地通過使用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 
    } 
} 
+0

但我使用的UIImagePickerController我想用它不AVFoundation框架 –

+0

實現,我想一個閃光模式不手電筒模式 –

+0

UIImagePickerView打開默認攝像機視圖來捕獲並有默認的控制來管理閃存。 –