UIImageView上的用户交互 [英] User Interaction on a UIImageView

查看:101
本文介绍了UIImageView上的用户交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些UIImageView,它们上面有按钮。

I have a number of UIImageView which have buttons on top of them.

我想在这些按钮后面的UIImageView上启用用户交互。

I would like to enable user interaction on the UIImageView behind these buttons.

我在IB中看到了这个选项,但是想知道在实际触摸UIImageView时如何触发一些代码。

I see the option in IB, but would like to know how to trigger some code when the UIImageView is actually touched.

如何做到这一点以及如何在代码而不是IB中设置为启用和禁用?

How does one do this and how is it set to enabled and disabled in the code rather than IB?

谢谢

推荐答案


当实际触摸UIImageView时如何触发一些代码。

how to trigger some code when the UIImageView is actually touched.

您有两种选择:


  1. 创建 UITapGestureRecognizer的实例(或另一个手势识别器),指定目标和动作方法。然后使用 - [UIView addGestureRecognizer:] 将手势识别器添加到图像视图中。适用于OS 3.2 +。

  1. Create an instance of UITapGestureRecognizer (or another gesture recognizer), specifying a target and an action method. Then add the gesture recognizer to the image view with -[UIView addGestureRecognizer:]. Works in OS 3.2+.

子类 UIImageView 并覆盖 -touches ... 方法。确保您创建的图像视图是自定义子类的实例。

Subclass UIImageView and override the -touches... methods. Make sure the image views you create are instances of your custom subclass.

有关详细信息,请参阅文档。

See the documentation for details.


如何在代码中设置启用和禁用而不是IB

how is it set to enabled and disabled in the code rather than IB

简单: imageView.userInteractionEnabled = YES;

这篇关于UIImageView上的用户交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆