Ios UICapgestureRecognitor发送方是手势,而不是ui对象

Ios UICapgestureRecognitor发送方是手势,而不是ui对象,ios,xcode,swift,uigesturerecognizer,Ios,Xcode,Swift,Uigesturerecognizer,我有一个名为的按钮,我给了它一个uigesturecognizer,这样iAction只有在长按按钮时才会运行。您可以通过向按钮本身添加一个ui长按手势识别器来完成此操作。然后控制并将该手势识别器拖动到如下功能: @IBAction func handleGesture(sender: UIGestureRecognizer) { if sender.state == UIGestureRecognizerState.Began { let labelTap1=

我有一个名为的按钮,我给了它一个
uigesturecognizer
,这样
iAction
只有在长按按钮时才会运行。您可以通过向按钮本身添加一个
ui长按手势识别器
来完成此操作。然后控制并将该手势识别器拖动到如下功能:

 @IBAction func handleGesture(sender: UIGestureRecognizer) {
    if sender.state == UIGestureRecognizerState.Began
    {
        let labelTap1=UITapGestureRecognizer(target: self, action: "labelTapped:")
        let alertController = UIAlertController(title: "**I want this to be the title of the button**", message:
            "This is the description of the function you pressed", preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,handler: nil))

        self.presentViewController(alertController, animated: true, completion: nil)
    }
}
正如您看到的那样,
UIAlertController
出现,我希望标题显示按钮当前标题。如果这个函数的发送者是按钮,我可以用
sender.currentTitle
调用它。当函数的发送者是手势时,如何获取与手势关联的按钮的标题


我在objective C中见过这样的帖子,但在Swift上没有。这就是当您长按按钮本身时,项目获取按钮描述的全部内容。

您可以通过其视图属性获取对该手势添加到的视图的引用。在本例中,您将其添加到按钮,以便view属性将返回按钮

let button = sender.view as? UIButton

是的,实际上和你说话的是手势识别器;是特工发现了这件事。然后,您需要询问它正在观看哪个视图。不确定这是否有帮助。