我是使用 UIImagePicker 的新手,所以请耐心等待。基本上,我定义了两个 UIButtons 来访问相机胶卷,一旦选择了图像,图像就会出现在我的 UIImageView 中。问题是当我从其中一个按钮中选择一个图像时,它出现在两个 UIImageViews 中,而不是一个。我基本上希望能够通过两个不同的按钮选择两张不同的照片。这是编码:
-(IBAction)getPhoto1:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popover1 = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover1 presentPopoverFromRect:CGRectMake(0.0, 0.0, 400., 400.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)getPhoto2:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
popover2 = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover2 presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
photo1.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
photo2.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}