如何检测 iOS 上 AnnotationView 的长压?
How to detect a long pressure on an AnnotationView on iOS?
我想在我的地图注释上重现 iOS 仪表板的效果,方法是在我长按其中一个仪表板后摇动它们。然而,我一直坚持检测用户何时长按了一个按钮。这是代码:
override init(annotation:MKAnnotation, reuseIdentifier identifier:String) {
bookingImageView = UIImageView(image: self.bookingImage)
...
let lpgr = UILongPressGestureRecognizer(target: self, action: Selector("handleLongPressure:"))
lpgr.minimumPressDuration = 2.0; //user must press for 2 seconds
bookingImageView.addGestureRecognizer(lpgr)
}
func handleLongPressure(notification: NSNotification){
wobble()
}
如果我将手势与注释或其 subview(bookingImageView)
相关联,则它不起作用。
您需要启用用户交互
bookingImageView.userInteractionEnabled = true
我找到的唯一解决方案是连接到拖动操作,这在某种程度上预示了长触摸。
我想在我的地图注释上重现 iOS 仪表板的效果,方法是在我长按其中一个仪表板后摇动它们。然而,我一直坚持检测用户何时长按了一个按钮。这是代码:
override init(annotation:MKAnnotation, reuseIdentifier identifier:String) {
bookingImageView = UIImageView(image: self.bookingImage)
...
let lpgr = UILongPressGestureRecognizer(target: self, action: Selector("handleLongPressure:"))
lpgr.minimumPressDuration = 2.0; //user must press for 2 seconds
bookingImageView.addGestureRecognizer(lpgr)
}
func handleLongPressure(notification: NSNotification){
wobble()
}
如果我将手势与注释或其 subview(bookingImageView)
相关联,则它不起作用。
您需要启用用户交互
bookingImageView.userInteractionEnabled = true
我找到的唯一解决方案是连接到拖动操作,这在某种程度上预示了长触摸。