0

我当前的代码是:

- (IBAction)cameraButtonAction:(id)sender {   
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.allowsEditing = NO;
    picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES]; 
}

这是调出默认相机,但是当我选择use它时不会保存图片。我努力了 :

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [self dismissModalViewControllerAnimated:YES];
}

我看过的每个教程,他们都使用 a 制作了一个自定义相机应用程序,UIImageView但这不是我想要做的,我不想在应用程序中显示图像并希望保留默认的相机功能。

4

1 回答 1

1

你的代码是正确的。但是你没有设置委托

您在这里缺少一行:

picker.delegate = self;

您需要在您的cameraButtonAction方法中添加它。

- (IBAction)cameraButtonAction:(id)sender
{   
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = NO;
    picker.sourceType = (sender == cameraButton) ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES]; 
}
于 2013-01-21T11:34:48.070 回答