【问题标题】:How to do a long press in Swift?如何在 Swift 中进行长按?
【发布时间】:2014-07-11 00:13:44
【问题描述】:

我正在尝试在 Swift 中实现对 mapView 的长按(以实现 this

我没有收到任何编译器错误,但是当我在模拟器中长按时,应用程序崩溃并显示“无法识别的选择器发送到实例”

我怀疑这与选择器有关(类似于 this)但我尝试过的每个组合都失败了

我在 viewDidLoad 中有这个:

var lpgr = UILongPressGestureRecognizer(target: self, action: "action") 

lpgr.minimumPressDuration = 2.0; 

mapView.addGestureRecognizer(lpgr)

这在 ViewController 类中:

func action(gestureRecognizer:UIGestureRecognizer) { 

println("long press") 

}

【问题讨论】:

  • “动作”应该是“动作:”
  • 就是这样 - 谢谢!将标记为答案
  • @0x7fffffff 他想接受你的回答。将其发布为答案:)

标签: swift


【解决方案1】:

方法的方法签名:

func action(gestureRecognizer:UIGestureRecognizer) { }

需要为其参数包含一个冒号。你应该使用这个。

var lpgr = UILongPressGestureRecognizer(target: self, action: "action:")

【讨论】:

    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2020-08-25
    • 2023-04-06
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多