gpt4 book ai didi

ios - 如何将其他参数传递给UITapGestureRecognizer?

转载 作者:行者123 更新时间:2023-12-01 17:20:13 28 4
gpt4 key购买 nike

如何将浮点值传递给函数handleTap?似乎我的参数签名设置正确,但是没有办法传递float值。

let tapped = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:digit:)))
tapped.numberOfTapsRequired = 1
mycontrol.addGestureRecognizer(handleTap)


func handleTap(recognizer: UITapGestureRecognizer, aFloat: Float) {
//do something here
}

最佳答案

您可以通过创建自己的TapGestureRecongnizer类来实现此目的,该类是UITapGestureRecognizer的子类。示例如下所示:

class MyTapGesture: UITapGestureRecognizer {
var floatValue = 0.0
}

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let tapped = MyTapGesture.init(target: self, action: #selector(handleTap))
tapped.floatValue = 5.0
tapped.numberOfTapsRequired = 1
view.addGestureRecognizer(tapped)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func handleTap(recognizer: MyTapGesture) {
print(recognizer.floatValue)
}
}

关于ios - 如何将其他参数传递给UITapGestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38416958/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com