ios - 用户界面 ImageView : add tap event from Interface Builder

标签 ios iphone swift xcode interface-builder

我知道如何以编程方式添加手势识别器。我想知道当我从 Interface Builder 中的 UIImageView 按住 Ctrl 键并拖动到代码中时,为什么我只能链接 Outlets 和 Outlets 集合而不是操作。我在 ImageView 上启用了用户交互,所以我想知道是否可以通过“拖动添加”的方式访问它的操作。

最佳答案

将用户交互设置为启用仅允许 ImageView 与手势识别器一起使用。他们没有 IBAction,因为他们不允许自己触摸。您必须将手势识别器拖到 ImageView 上才能使其工作。

来自UIImageView class ref :

Image views ignore user events by default. Normally, you use image views only to present visual content in your interface. If you want an image view to handle user interactions as well, change the value of its userInteractionEnabled property to true. After doing that, you can attach gesture recognizers or use any other event handling techniques to respond to touch events or other user-initiated events.

关于ios - 用户界面 ImageView : add tap event from Interface Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38647622/

相关文章:

ios - 将数据保存到核心数据 - Swift

iphone - 哪个谷歌地图版本适用于 ios 5

swift - UIButton的 Action 自动需要延迟响应

swift - RealmObject Equatable 冗余消息

ios - 如何使用 XMPPFramework 在 XMPP IOS 中发送可用节?

ios - 关闭 UIViewController 时停止视频流

ios - 在 iOS 13 全屏中呈现模式

ios - iOS 中可以进行实时音频处理吗?

iphone - iOS设备上的乐器-无法象征,因为该应用未显示在下拉菜单中

ios - 当我使用 StoreKit 的 requestReview 功能时,有什么方法可以知道用户是否点击了提交或不现在或取消按钮?