【发布时间】:2015-06-12 13:59:11
【问题描述】:
我想在 mapView 中缩放 PinImages(当它缩小或缩小时),为此我这样做:
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
}
在委托方法之后,我找到了比例,并想在 mapView 注释的循环中使用 resizePin 方法来调整它们的大小
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
}
}
不知道如何使它正确,以及异常的原因是什么。有什么想法吗?
【问题讨论】:
标签: ios swift nsarray mkannotation