我已经看到这回答了 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.cclass 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传递参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)