简体   繁体   中英

How to detect a long pressure on an AnnotationView on iOS?

I would like to reproduce the effect of the iOS dashboard on my map annotation by wobbling them once I long press one of them. Yet I am stuck at detecting when a user has long pressed one. Here is code:

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()
}

It does not work, either if I associate the gesture to the annotation or to its subview(bookingImageView) .

您需要设置启用用户交互

bookingImageView.userInteractionEnabled = true

我发现的唯一解决方案是连接到以某种方式需要长时间触摸的拖动操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM