我目前的代码是:
- (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];
}
我看过的每个教程,他们使用UIImageView
制作自定义相机应用程序,但这不是我想要做的,我不想在应用程序中显示图像并希望保留默认的相机功能。
答案 0 :(得分: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];
}