我已经实现了一个PickerController让用户选择一个图像,但我希望用户选择的图像显示在我拥有的UIImageView上。
我使用以下内容进入相机胶卷:
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
[self presentModalViewController: picker animated: YES];
}
它会调出相机胶卷,用户可以在其中点击照片。但是,点击后,它会返回到主视图,这很明显......但是如何为按钮或用户选择的图像指定动作。像UIOKButton
这样的东西?
类似的东西:
if ([UIImagePickerController presentModalViewController:nil image:nil] == UIOKButton ) {
NSArray *images = [UIImagePickerController images];
for(UIImage* pickerImage in [UIImagePickerController images])
{
myUIImage.image setImage pickerImage;
//^in the view
}
我不确定该怎么做。
所有回复都表示赞赏。
谢谢!
答案 0 :(得分:0)
- (void) makeUIImagePickerControllerForCamera:(BOOL)camera {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[picker setMediaTypes:[NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil]];
[self presentModalViewController: picker animated: YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Dismiss the picker
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
// Get the image from the result
UIImage* image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
myUIImage.image = image;
}
答案 1 :(得分:0)