【问题标题】:multiple UIImageViews with UIImagePickers带有 UIImagePickers 的多个 UIImageViews
【发布时间】:2011-05-15 10:48:12
【问题描述】:

我有 3 个 UIImageViews 我想为其加载图像。 对于 1 张图像,这不是问题,但如何缩放到 3 张? 下面的代码就是我现在所拥有的。

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES];

}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];    
UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
[my_image_1 setImage:image forState:UIControlStateNormal];

}

【问题讨论】:

  • 您想在所有 3 个UIImageViews 上加载相同的图像?如果是这样,那么只需为所有图像视图执行setImage:forState:,而不仅仅是第一个。
  • 我想加载 3 张不同的图片。所以 3 个按钮来加载图像。 - 埃里克S

标签: iphone uiimagepickercontroller


【解决方案1】:

你看过thisthis吗?他们似乎指向这个resource

编辑

根据您的评论,我建议您在您的班级中声明一个 ivar imageViewToSet 并在问题中更改您的方法,如下所示,

-(IBAction) getPhoto:(id) sender {
    // Add code to identify the sender(button) via tags or outlets and set imageViewToSet to the mapped imageView through a switch or if statement.
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentModalViewController:picker animated:YES];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];    
    imageViewToSet.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}

【讨论】:

  • 我确实遇到了这些链接。我不想同时选择多个图像。在 ViewController 我有 3 个图像和 3 个按钮来选择图像。我可以以某种方式将“发件人”传递给 imagePickerController 吗?
  • 根据您的评论添加了编辑。这符合您的需要吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-12
相关资源
最近更新 更多