我遵循了使用UIImagePickerController
自定义叠加层的apple docs方法。现在它非常简单,我在叠加视图上只有一个按钮。此按钮的目标为takePic
。唯一的问题是,由于我没有使用默认的相机控件,因此在捕获图片后永远不会调用imagePickerController
委托方法,
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
我认为这种方法通常在用户捕获图片后点击默认叠加层并点击"选择照片"。然而,在这个叠加层中,我想要的只是一个"拍照"拍摄照片并保存的按钮。
这是我的代码:
-(void)takePic
{
[cameraUI takePicture];
NSLog(@"take pic called");
}
// For responding to the user accepting a newly-captured picture or movie
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
NSLog(@"Finished picking media");
NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
UIImage *originalImage, *imageToSave;
// Handle a still image capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
== kCFCompareEqualTo) {
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
imageToSave = originalImage;
NSLog(@"image Saved");
// Save the new image (original or edited) to the Camera Roll
UIImageWriteToSavedPhotosAlbum (imageToSave, nil, nil , nil);
}
// Handle a movie capture
if (CFStringCompare ((CFStringRef) mediaType, kUTTypeMovie, 0)
== kCFCompareEqualTo) {
NSString *moviePath = [[info objectForKey:
UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (
moviePath, nil, nil, nil);
}
}
[[picker parentViewController] dismissModalViewControllerAnimated: YES];
}
正如我之前提到的,imagePickerController:didFinishPickingMediaWithInfo:
永远不会被调用。如何将图片保存到相机胶卷?
答案 0 :(得分:0)
您是否将对象设为delegate
的{{1}}?
如果你的cameraUI是ImagePicker
,你应该在某个时候,在呈现cameraUI之前,让代码(UIImagePickerController *)
或任何控制器都有委托方法。