ios – 使用UITapGestureRecognizer传递参数

ios – 使用UITapGestureRecognizer传递参数,第1张

概述有什么办法可以用UITapGestureRecognizer传递参数吗? 我已经看到这回答了 Objective-c但是找不到swift的答案 test.userInteractionEnabled = truelet tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped4:"))/ 有什么办法可以用UITapGestureRecognizer传递参数吗?
我已经看到这回答了 Objective-c但是找不到swift的答案
test.userInteractionEnabled = truelet tapRecognizer = UITapGestureRecognizer(target: self,action: Selector("imageTapped4:"))// Something like text.myParamatertest.addGestureRecognizer(tapRecognizer)

然后在func imageTapped4(){}下接收myParameter

解决方法 一种方法是将UITapGestureRecognizer子类化,然后设置属性,我在下面发布了一个例子.您还可以检查发件人并检查是否等于某个标签,类,字符串,e.t.c
class VIEwController: UIVIEwController {    @IBOutlet weak var label1: UILabel!    @IBOutlet weak var image: UIImageVIEw!    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // Do any additional setup after loading the vIEw,typically from a nib.        image.userInteractionEnabled = true;        let tappy = MyTapGesture(target: self,action: #selector(self.tapped(_:)))        image.addGestureRecognizer(tappy)        tappy.Title = "val"    }    func tapped(sender : MyTapGesture) {        print(sender.Title)        label1.text = sender.Title    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()        // dispose of any resources that can be recreated.    }}class MyTapGesture: UITapGestureRecognizer {    var Title = String()}

SO上有很多例子,看看,祝你好运.

总结

以上是内存溢出为你收集整理的ios – 使用UITapGestureRecognizer传递参数全部内容,希望文章能够帮你解决ios – 使用UITapGestureRecognizer传递参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101396.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存