对 iPhone 中的图像进行操作

Posted

技术标签:

【中文标题】对 iPhone 中的图像进行操作【英文标题】:Action on image in iphone 【发布时间】:2011-12-23 09:58:18 【问题描述】:

我正在创建一个程序,在该程序中我在视图上添加一个图像视图,并且我希望仅在单击图像后,应该出现另一个详细视图。

NSString *imageName = [NSString stringWithFormat:[dic objectForKey:@"img"]]; 
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.view addSubView:imageView];

详细视图应与导航控制器一起出现。请帮我解决这个问题

【问题讨论】:

你为什么不使用UIButton 你的意思是点击uiimageview,需要加载一些detailView,是不是正确的场景? 见***.com/questions/4930449/… 您可以将图像加载到 UIButton 中。 是的,莎拉,感谢大家的回复 【参考方案1】:

做一件事,添加UIButton 并将其设置为自定义并将图像设置为UIButton 的背景,然后您将能够单击相同并导航到其他视图。怎么样?

【讨论】:

【参考方案2】:

您可以继承 UIImageView 并覆盖 touchesEnded 方法。这样,当有人触摸您的 UIImageView 时,您可以调用您的 UINavigationController 并推送任何其他控制器。

@interface YourImageView : UIImageView



在您的实现文件中键入:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

    // push view controller here or use a delegate 
    // and push the view controller somewhere else

确保您还将 UIImageView 的 userInteractionEnabled 属性设置为“YES”

【讨论】:

【参考方案3】:

我曾经遇到过类似的问题,这里是解决方案的链接:UIButton inside UIImageView does not respond to taps

(这是对上面给出的答案之一的扩展......)

【讨论】:

以上是关于对 iPhone 中的图像进行操作的主要内容,如果未能解决你的问题,请参考以下文章

裁剪图像更改 iPhone 中的旋转

iPhone ALAssetsLibrary 获取所有图像并进行编辑

从 iPhone 中的视频帧中获取图像

iPhone模拟器中缺少一些文件夹?

如何在 iPhone 中以高质量调整图像大小

如何在 iPhone 应用程序中执行图像编辑?