gpt4 book ai didi

ios - NSArray 元素无法匹配 mapView.annotations 循环中的 Swift 数组元素类型

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:45 25 4
gpt4 key购买 nike

我想在 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
}

在委托(delegate)方法中我找到比例并想在 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
}
}

不知道如何正确处理,以及异常的原因是什么。有什么想法吗?

最佳答案

mapView.annotations 属性是 MKAnnotation 类型。如果您想修改每个注释的 View ,请尝试以下代码:

for annotation in mapView.annotations {
let view = mapView.viewForAnnotation(annotation)
// modify the view.
}

关于ios - NSArray 元素无法匹配 mapView.annotations 循环中的 Swift 数组元素类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30804920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com