这是我在iphone上更改闪光模式的代码。
在ios7.0中有效:flashmode(0,1,-1)
在ios7.1中,不能正常工作:flashmode(0,0,0)
//UIImagePickerControllerCameraFlashModeOff = -1,
//UIImagePickerControllerCameraFlashModeAuto = 0,
//UIImagePickerControllerCameraFlashModeOn = 1
NSInteger flashMode = self.pickerReference.cameraFlashMode;
NSLog(@"flashmode %i",flashMode);
if (flashMode == UIImagePickerControllerCameraFlashModeAuto) {
[(UIButton *)sender setImage:[UIImage imageNamed:@"flashYesComposeButton.png"] forState:UIControlStateNormal];
self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
}
else if (flashMode == UIImagePickerControllerCameraFlashModeOn) {
[(UIButton *)sender setImage:[UIImage imageNamed:@"flashNoComposeButton.png"] forState:UIControlStateNormal];
self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
}
else if (flashMode == UIImagePickerControllerCameraFlashModeOff)
{
[(UIButton *)sender setImage:[UIImage imageNamed:@"flashAutoComposeButton.png"] forState:UIControlStateNormal];
self.pickerReference.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
答案 0 :(得分:7)
我在
之前遇到了那个bug问题在于,无论ios 7.1中的实际闪存状态是什么,它总是返回UIImagePickerControllerCameraFlashModeAuto
。有趣的是,如果你将闪光模式设置为UIImagePickerControllerCameraFlashModeOff
,闪光灯将真的关闭,但如果你问状态,它仍然是UIImagePickerControllerCameraFlashModeAuto
。
所以我通过保留自己的“flashState”解决了我的问题。单击时,我手动更改自己的状态,并且永远不会相信发回的那个但是UIImagePickerController。
@property (nonatomic) UIImagePickerControllerCameraFlashMode flashMode;
单击按钮时:
if (self.flashMode == UIImagePickerControllerCameraFlashModeAuto) {
//toggle your button to "on"
self.flashMode = UIImagePickerControllerCameraFlashModeOn;
}else if (self.flashMode == UIImagePickerControllerCameraFlashModeOn){
//toggle your button to "Off"
self.flashMode = UIImagePickerControllerCameraFlashModeOff;
}else if (self.flashMode == UIImagePickerControllerCameraFlashModeOff){
//toggle your button to "Auto"
self.flashMode = UIImagePickerControllerCameraFlashModeAuto;
}