gpt4 book ai didi

ios - 从摄像头或库中选择多个 ImageView 的图像

转载 作者:行者123 更新时间:2023-11-29 11:01:22 25 4
gpt4 key购买 nike

我的 view controller 上有 3 个 Image views(Purpose Before,During,After)。我需要分别为每个 View 选择图像。

此任务的指定方法是:

 -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image;
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[_imgView setImage:image];
[self dismissViewControllerAnimated:YES completion:NULL];
}

但是如何通知此方法有关哪个按钮调用了图像选择器以及分别选择/显示 View 中的图像。

最佳答案

添加一个“私有(private)”(是的,我不知道这样的东西)ivar 来保存对 selectedImageView 的引用

@interface MyViewController ()

@property (nonatomic, strong) UIImageView *selectedImageView;

@end

然后当 imageView 被选中时,使用这个新的 ivar 来保持对当前事件 imageView 的引用

- (void)imageViewTapped:(id)sender
{
// This assumes the use of a gesture recognizer but you can substitute your usual method
// of detecting the imageView that you want to edit.
self.selectedImageView = [sender view];
}

现在你的委托(delegate)看起来像这样

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.selectedImageView.image = info[UIImagePickerControllerOriginalImage];
self.selectedImageView = nil;

[self dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 从摄像头或库中选择多个 ImageView 的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15782085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com