美文网首页iOS Developer
在使用 UILongPressGestureRecognizer

在使用 UILongPressGestureRecognizer

作者: BearLin | 来源:发表于2017-01-18 11:50 被阅读0次

    在使用 UILongPressGestureRecognizer 时,想在长按的手势后弹出提示框 UIAlertController,会遇到如下提示:

    Attempt to present <UIAlertController: 0x7fd57384e8e0>  on <xxxxxxxx> which is already presenting (null)
    

    问题原因:
    一次长按手势会调用两次 Action,需要在执行所需操作的前判断 gesture 的状态 (有人知道为什么会执行两次的请告知,谢谢~)


    解决方案:

    @IBAction func longPressedAction(_ gesture: UIGestureRecognizer) {
        guard gesture.state == .began else {
              return
        }
        // 执行所需操作
    }
    

    (作为经验记录,有错误希望指出,感谢~🙏)

    相关文章

      网友评论

        本文标题:在使用 UILongPressGestureRecognizer

        本文链接:https://www.haomeiwen.com/subject/ddnvbttx.html