I want to zoom PinImages in mapView(when it zoom out or in), for this I do :
func resizePin(scale: CGFloat, image: UIImage) -> UIImage {
var newSize = CGSizeMake(image.size.width * scale, image.size.height * scale)
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
image.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
var newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}
after in delegate method I find scale and want to use resizePin method inside the loop of mapView annotations, to resize them all
func mapView(mapView: MKMapView!, regionWillChangeAnimated animated: Bool) {
oldZoomLatitude = mapView.region.span.latitudeDelta
oldZoomLongitude = mapView.region.span.longitudeDelta
}
func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) {
newZoomLatitude = mapView.region.span.latitudeDelta
newZoomLongitude = mapView.region.span.longitudeDelta
mapScale = (newZoomLongitude! / oldZoomLongitude!)
println(mapScale)
for annotation in mapView.annotations as [MKAnnotationView] { // EXCEPTION - fatal error: NSArray element failed to match the Swift Array Element type
}
}
dont get how to make it right, and what is a reason of exception. Any ideas?
The
mapView.annotations
property is of typeMKAnnotation
. If you'd like to modify the view for each annotation, try the below code: