3 uiimageview ios uitapgesturerecognizer swift
我在 ViewController 上创建了 6 个 UIImageView,稍后我将向所有这些视图添加 TapGestureRecognizer。
我想让它根据单击的图像,另一个 ViewController 将打开并显示某些信息。
为此,我需要知道单击了哪个图像。我该如何在 Swift 中做到这一点?
UIGestureRecognizer 有属性“view”,该属性是您将其添加到的视图。对于这个例子,imageView.
func tap(gesture: UIGestureRecognizer) {
println(gesture.view!.tag) // You can check for their tag and do different things based on tag
}
let img = UIImageView()
img.userInteraction = true
img.tag = 0
img.addGestureRecognizer(UITapGestureRecognizer(self, action: "tap:"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4572 次 |
| 最近记录: |