User Interaction on a UIImageView(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.
你有两个选择:
创建
UITapGestureRecognizer(或其他手势识别器)的实例,指定目标和操作方法.然后使用-[UIView addGestureRecognizer:]将手势识别器添加到图像视图中.适用于 OS 3.2+.
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 上的用户交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIImageView 上的用户交互
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
