iOS 7.1 imagePicker CameraFlashMode不指示Flash状态
我有iPhone应用程序覆盖相机与自定义视图。 我有一个button来切换相机闪光灯模式,这是代码
switch ([self.imagePickerController cameraFlashMode]) { case UIImagePickerControllerCameraFlashModeAuto: [self.imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn]; return @"On"; break; case UIImagePickerControllerCameraFlashModeOn: [self.imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff]; return @"Off"; break; case UIImagePickerControllerCameraFlashModeOff: [self.imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeAuto]; return @"Auto"; break; default: break; }
这是我的问题:在iOS 7.0x上工作得非常好,但在iOS 7.1中,cameraFlashMode属性返回UIImagePickerControllerCameraFlashModeAuto,无论其实际状态如何。
闪光模式确实改变,但我没有得到任何迹象。 任何线索? 谢谢
我解决了这个问题:
@property (nonatomic) NSInteger flashMode; if (_flashMode == UIImagePickerControllerCameraFlashModeAuto) { _flashMode = UIImagePickerControllerCameraFlashModeOff; } else if (_flashMode == UIImagePickerControllerCameraFlashModeOff) { _flashMode = UIImagePickerControllerCameraFlashModeOn; } else if (_flashMode == UIImagePickerControllerCameraFlashModeOn) { _flashMode = UIImagePickerControllerCameraFlashModeAuto; } _cameraPicker.cameraFlashMode = (UIImagePickerControllerCameraFlashMode)_flashMode;
好吧,我仔细研究了这个,并在网上find了这个有用的文章:
我接受了他们的build议,现在我在用户拍摄照片之前设置了闪光灯设置。 我不是检查相机当前的闪光灯设置,而是检查我的闪光灯button的titleLabel文字,以查看用户想要的闪光灯设置:
这里是我提出的代码,现在为我解决了这个问题。 我希望这可以帮助你解决iOS 7.0中不存在的问题,但现在在iOS 7.1上。
#define deviceHasCameraFlash [UIImagePickerController isFlashAvailableForCameraDevice:UIImagePickerControllerCameraDeviceRear] - (void)capturePhoto { if (self.cameraDevice != UIImagePickerControllerCameraDeviceFront && deviceHasCameraFlash) { if ([self.flashButton.titleLabel.text isEqualToString:@"Auto"]) { self.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto; } else if ([self.flashButton.titleLabel.text isEqualToString:@"Off"]) { self.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff; } else if ([self.flashButton.titleLabel.text isEqualToString:@"On"]) { self.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn; } } [self takePicture]; }
尝试使用AVCaptureDevice:
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); if (captureDeviceClass != nil) { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; [device lockForConfiguration:nil]; if ([device hasTorch]) { if (device.torchMode == AVCaptureTorchModeAuto) { NSLog(@"Auto"); } if (device.torchMode == AVCaptureTorchModeOn) { NSLog(@"On"); } if (device.torchMode == AVCaptureTorchModeOff) { NSLog(@"Of"); } } if ([device hasFlash]) { if (device.flashMode == AVCaptureFlashModeAuto) { NSLog(@"Auto"); } if (device.flashMode == AVCaptureFlashModeOn) { NSLog(@"On"); } if (device.flashMode == AVCaptureFlashModeOff) { NSLog(@"Of"); } } [device unlockForConfiguration]; }
上面的答案没有为我在iOS 7.1中工作@daidai这就是我所做的,这对我工作
在你的.h文件属性flashMode
- (void)didTapFlash:(id)sender { if (self.flashMode == UIImagePickerControllerCameraFlashModeAuto) { //toggle your button to "on" [self.imagePicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn]; [self.flashButton setImage:[UIImage imageNamed:@"flashOn"] forState:UIControlStateNormal]; self.flashMode = UIImagePickerControllerCameraFlashModeOn; NSLog(@"On state: %d", self.flashMode); }else if (self.flashMode == UIImagePickerControllerCameraFlashModeOn){ //toggle your button to "Off" [self.imagePicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeOff]; [self.flashButton setImage:[UIImage imageNamed:@"flashOf"] forState:UIControlStateNormal]; self.flashMode = UIImagePickerControllerCameraFlashModeOff; NSLog(@"Of state: %d", self.flashMode); }else if (self.flashMode == UIImagePickerControllerCameraFlashModeOff){ //toggle your button to "Auto" [self.imagePicker setCameraFlashMode:UIImagePickerControllerCameraFlashModeAuto]; [self.flashButton setImage:[UIImage imageNamed:@"flashAuto"] forState:UIControlStateNormal]; self.flashMode = UIImagePickerControllerCameraFlashModeAuto; NSLog(@"Auto state: %d", self.flashMode); } }