5

我的自定义相机覆盖上有一个按钮,可以调用此方法:

- (void) changeFlash:(id)sender
{
    //UIImagePickerControllerCameraFlashModeOff  = -1,
    //UIImagePickerControllerCameraFlashModeAuto = 0,
    //UIImagePickerControllerCameraFlashModeOn   = 1
    NSLog(@"before %d", self.picker.cameraFlashMode);
    switch (self.picker.cameraFlashMode) {
        case UIImagePickerControllerCameraFlashModeAuto:
            [(UIButton *)sender setImage:[UIImage imageNamed:@"flashOn"] forState:UIControlStateNormal];
            self.picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
            break;
        case UIImagePickerControllerCameraFlashModeOn:
            [(UIButton *)sender setImage:[UIImage imageNamed:@"flashOff"] forState:UIControlStateNormal];
            self.picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
            break;

        case UIImagePickerControllerCameraFlashModeOff:
            [(UIButton *)sender setImage:[UIImage imageNamed:@"flashAuto"] forState:UIControlStateNormal];
            self.picker.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
            break;
    }
    NSLog(@"after %d", self.picker.cameraFlashMode);

}

self.picker.cameraFlashMode 在更改前后始终为 0。我究竟做错了什么?

此外,闪光灯从不工作,即使它据说卡在 UIImagePickerControllerCameraFlashModeAuto 中。

4

1 回答 1

0

self.picker 为零。这是一个常见的错误,您需要经常检查,因为与 Java 和其他语言不同,在 Objective-C 中向 nil 发送消息是有效的。

于 2013-03-10T15:46:43.283 回答