Trying to animate my custom pin image.
However I cannot find a way to access the MKAnnotationView.
This task is trivial for example when you use
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
}
As you have the view right there.
But I want to be able to animate a set of pin the I have zoomed into the area of.
Using the built in mapView property of annotations I can obtain the pins I require.
So within
func findThePins(searchName:String) {
var foundItems = [Client]()
for aPin in mapView.annotations as! [Client] {
if aPin.clientName.uppercaseString.rangeOfString(searchName.uppercaseString) != nil {
foundItems.append(aPin)
}
}
if !foundItems.isEmpty {
println("move map - \(foundItems.count)")
// moves to show the area of the screen containing the pins
mapView.showAnnotations(foundItems, animated: true)
// How to animate those pins in foundItems
}
}
How can I access the view so I can then animate. I have a feeling Im going bout this the wrong way.
Example animation that would work fine in the didSelectAnnotationView
UIView.animateWithDuration(1.0, delay: 0.0, options: nil, animations: { () -> Void in
pinView.transform = CGAffineTransformMakeScale(2.0, 2.0)
}, completion: { (completed) -> Void in
pinView.transform = CGAffineTransformIdentity
})
Thanks
Problem Solved!
let clientAnnotation = self.mapView.viewForAnnotation(client)