5
我正在使用帶自定義攝像頭覆蓋視圖的UIImagePickerController,並希望添加自定義按鈕以在自動,開啓和關閉之間切換閃光模式。這裏是按鈕調用的方法:使用自定義攝像頭覆蓋更改閃光模式
- (void)didTapFlash:(id)sender
{
if (self.imagePickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeAuto)
{
[imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
[self.flashButton setImage:[UIImage imageNamed:@"flashIconOn.png"] forState:UIControlStateNormal];
}
else if (self.imagePickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeOn)
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
[self.flashButton setImage:[UIImage imageNamed:@"flashIconOff.png"] forState:UIControlStateNormal];
}
else if (self.imagePickerController.cameraFlashMode == UIImagePickerControllerCameraFlashModeOff)
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
[self.flashButton setImage:[UIImage imageNamed:@"flashIconAuto.png"] forState:UIControlStateNormal];
}
}
問題是這不起作用。一旦呈現控制器,self.imagePickerController.cameraFlashMode的值永遠不會改變。閃光值可以在出現之前更改,但一旦閃現值將始終返回值0(自動)。奇怪的部分是,即使該值不會改變,閃光的行爲就好像它這樣做,如果我上面的代碼更改爲:
- (void)didTapFlash:(id)sender
{
if (flashButton.tag == 0)
{
[imagePickerController setCameraFlashMode:UIImagePickerControllerCameraFlashModeOn];
self.flashButton.tag = 1;
[self.flashButton setImage:[UIImage imageNamed:@"flashIconOn.png"] forState:UIControlStateNormal];
}
else if (flashButton.tag == 1)
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.flashButton.tag = -1;
[self.flashButton setImage:[UIImage imageNamed:@"flashIconOff.png"] forState:UIControlStateNormal];
}
else if (flashButton.tag == -1)
{
self.imagePickerController.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
self.flashButton.tag = 0;
[self.flashButton setImage:[UIImage imageNamed:@"flashIconAuto.png"] forState:UIControlStateNormal];
}
}
一切正常。 (flashButton.tag只是存儲flash值)
有沒有人知道這裏發生了什麼?爲什麼cameraFlashMode的值始終爲0(在NSLog語句中以及直接通過調試器進行檢查時),即使閃存表現得像設置正確一樣?
我也有這個問題。你解決了這個問題嗎? – hmlasnk
如果您使用問題第二部分的代碼,則閃光燈將按預期工作,但新值不會在imagePickerController.cameraFlashMode上更新,因此它的值必須存儲在別處(在上面的代碼中,我將它存儲在標籤)。我仍然不知道它爲什麼起作用的原因。我想CameraFlashMode只是將新值傳遞給一個私有屬性並重置。 –
我認爲iOS 7.1有bug。這是這個問題。我以前檢查它是與iOS 7.0並完美工作。但不適用於iOS 7.1。 – hmlasnk