gpt4 book ai didi

ios - 从绑定(bind)到多个 UIButtons 的 GestureRecognizer 获取发件人信息

转载 作者:行者123 更新时间:2023-11-29 02:09:49 25 4
gpt4 key购买 nike

所以我有一个 UILongPressGestureRecognizer 连接到

@IBAction func PresentPlayerInfo(sender: UIGestureRecognizer){
if let button = sender.view as? UIButton {
buttonSourceFrame = button.frame.origin}
performSegueWithIdentifier("PVC", sender: self)
}

buttonSourceFrame 然后传递给 prepareForSegue

中的下一个 ViewController

我想将这 1 个 UILongPressGestureRecognizer 连接到多个 UIButton,这样我就不必为每个 创建一个 UILongPressGestureRecognizer >UI 按钮

但是当我将多个 UIButton 连接到单个 gestureRecognizer 时...无论我按哪个按钮,转场都很好,但传递的 CGPoint 总是UIButton 位于列表顶部的那个(这里是 3),而不是确切按下的 UIButtonCGPoint

enter image description here

是否可以将一个 GestureRecognizer 连接到许多 UIButton 并仍然获得发件人信息...或者我必须创建一个 GestureRecognizer 每个 UIButton?

最佳答案

将手势识别器连接到 viewController 的主视图。然后,在您的 @IBAction 中,您必须确定被点击的 View :

@IBAction func PresentPlayerInfo(sender: UIGestureRecognizer){
var tappedView: UIView?
var loc = sender.locationInView(self.view) // self.view is the parent view of the buttons

if (CGRectContainsPoint(self.button1.frame, loc)) {
tappedView = self.button1
}
else if (CGRectContainsPoint(self.button2.frame, loc)) {
tappedView = self.button2
}


performSegueWithIdentifier("PVC", sender: tappedView)
}

关于ios - 从绑定(bind)到多个 UIButtons 的 GestureRecognizer 获取发件人信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407167/

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