Ratka
Ratka

Reputation: 37

Cannot tap on annotation when animating

I've got my custom annotation. I animate it from time to time:

 UIView.animateWithDuration(duration, delay: 0, options: .CurveLinear, animations: {
                        customAnnotation.coordinate = newCoordinate

and while this is happening I can't tap on it to call mapView:didSelectAnnotationView

I even added UIButton as a subview:

let button = UIButton(frame: CGRect(x: 7.25, y: 17, width: 37, height: 15))
    let text = customAnnotation.displayedName
    button.setTitle(text, forState: .Normal)
    button.backgroundColor = UIColor.blackColor()
    button.setTitleColor(UIColor.greenColor(), forState: .Normal)
    button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
    customAnnotationView?.addSubview(button)

in mapView:viewForAnnotation but it doesn't work either. Any ideas?

Upvotes: 1

Views: 86

Answers (2)

pbodsk
pbodsk

Reputation: 6876

One of the other UIViewAnimationOptions parameters you can pass to in options is .AllowUserInteraction

public static var AllowUserInteraction: UIViewAnimationOptions { get } // turn on user interaction while animating

To pass more than one parameter to options you pass them in an array, like so:

UIView.animateWithDuration(duration, delay: 0, options: [.CurveLinear, .AllowUserInteraction], animations: {
                    customAnnotation.coordinate = newCoordinate

Hope that helps you.

Upvotes: 0

Hitesh Surani
Hitesh Surani

Reputation: 13537

Use below might be work for you.

 View.animateWithDuration(duration, delay: 0, options: .CurveLinear | .AllowUserInteraction , animations: {
                            customAnnotation.coordinate = newCoordinate
})

Upvotes: 1

Related Questions