【问题标题】:Action on image in iphone对 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,是不是正确的场景?
  • 您可以将图像加载到 UIButton 中。
  • 是的,莎拉,感谢大家的回复

标签: iphone ios


【解决方案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

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

      【讨论】:

        猜你喜欢
        • 2021-12-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-08
        • 1970-01-01
        • 2020-11-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多