我知道如何以编程方式添加手势识别器。我想知道当我从 Interface Builder 中的 UIImageView 按住 Ctrl 键并拖动到代码中时,为什么我只能链接 Outlets 和 Outlets 集合而不是操作。我在 ImageView 上启用了用户交互,所以我想知道是否可以通过“拖动添加”的方式访问它的操作。
最佳答案
将用户交互设置为启用仅允许 ImageView 与手势识别器一起使用。他们没有 IBAction,因为他们不允许自己触摸。您必须将手势识别器拖到 ImageView 上才能使其工作。
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/