我正在尝试实现一个 MKCircle,它会随着滑块的变化而增加或减少半径。我遇到的问题是,当重新绘制圆圈时,它根本不平滑。我已经阅读了其他一些帖子,它们似乎表明您必须创建 MKCircle 的子类并以某种方式做到这一点,但是每当我查看示例代码时,我都很难理解,因为它通常不在 Swift 3 中。有人可以告诉我怎么做?这是我更改滑块时的代码:
func sliderValueChanged(_ sender:UISlider!) {
if (!map.selectedAnnotations.isEmpty) {
for overlay in map.overlays {
var temp : MKAnnotation = (map.selectedAnnotations.first)!
if (overlay.coordinate.latitude == temp.coordinate.latitude && overlay.coordinate.longitude == temp.coordinate.longitude) {
let newCirc : MKCircle = MKCircle(center: temp.coordinate, radius: CLLocationDistance(Float(sender.value*1000)))
let region: MKCoordinateRegion = MKCoordinateRegionForMapRect(newCirc.boundingMapRect)
let r: MKCoordinateRegion = map.region
if (region.span.latitudeDelta > r.span.latitudeDelta || region.span.longitudeDelta > r.span.longitudeDelta){
map.setRegion(region, animated: true)
}
map.add(MKCircle(center: temp.coordinate, radius: CLLocationDistance(Float(sender.value*1000))))
map.remove(overlay)
break
}
}
}
}