编辑:在下面的代码中添加了正确的代码。工作中。

我有一个标签,它在运行时位于我的游戏顶部。我希望能够长按标签并调出主菜单。现在,当我长按时,应用程序崩溃并显示以下错误。

错误:



我所拥有的基础知识:

var gameTopTitle = UILabel()

//this is all after my gameTopTitle is added to the screen
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.longTap))
gameTopTitle.addGestureRecognizer(longGesture)
gameTopTitle.isUserInteractionEnabled = true

和功能
    func longTap(sender : UIGestureRecognizer){
    print("Long tap")
    if sender.state == .ended {
        print("UIGestureRecognizerStateEnded")
        //Do Whatever You want on End of Gesture
    }
    else if sender.state == .began {
        print("UIGestureRecognizerStateBegan.")
        //Do Whatever You want on Began of Gesture
    }
}

最佳答案

试试这个

let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.longTap))

我希望这可以帮助你

关于ios - UILabel长按识别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43060122/

10-14 20:26