在 UITableViewCell 上时,MKPointAnnotation 在 mapView 上闪烁。如何阻止它?
MKPointAnnotation flickers on mapView when on UITableViewCell. How to stop it?
我在 UITableViewCell 上有一个 mapView,当我显示 mapView 时,注释闪烁。我不确定如何让它停止。
我通过
设置了mapView
if let event = event {
mapView.showsUserLocation = true
mapView.isUserInteractionEnabled = true
let center = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude)
//Create annotation
let annotation = MKPointAnnotation()
annotation.coordinate = center
mapView.addAnnotation(annotation)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))
mapView.setRegion(region, animated: true)
}
我已确保注释只添加到地图一次。
这是它发生的视频 https://youtu.be/lkpn9Rqd0AE
此外,这只会在没有用户交互时发生,如果我滚动它就会停止,如果我与地图交互它就会停止闪烁。
我创建了一个测试项目,它没有这个问题,即使我复制并粘贴了上面的代码。我不知道有什么不同。
使用定时器怎么样?
var timer: Timer!
func foo {
timer = Timer.scheduledTimer(timeInterval: 1.0,
target: self,
selector: #selector(self.update),
userInfo: nil,
repeats: true)
timer.fire()
}
func update(tm: Timer) {
for annotation in self.mapView.annotations {
if annotation is MKUserLocation { continue }
if let annotationView = mapView.view(for: annotation) {
annotationView.isHidden = !annotationView.isHidden
}
}
}
别忘了停止计时器。
timer.invalidate()
联系苹果开发者支持后,他们告诉我这是一个错误,不是我的代码造成的。
Apple 已表示要删除和添加礼仪以找出破坏它的地方,或者使用他们修复错误的最新版本 Xcode。下载最新版本 Xcode 解决了我的问题。
我在 UITableViewCell 上有一个 mapView,当我显示 mapView 时,注释闪烁。我不确定如何让它停止。
我通过
设置了mapViewif let event = event {
mapView.showsUserLocation = true
mapView.isUserInteractionEnabled = true
let center = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude)
//Create annotation
let annotation = MKPointAnnotation()
annotation.coordinate = center
mapView.addAnnotation(annotation)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))
mapView.setRegion(region, animated: true)
}
我已确保注释只添加到地图一次。 这是它发生的视频 https://youtu.be/lkpn9Rqd0AE 此外,这只会在没有用户交互时发生,如果我滚动它就会停止,如果我与地图交互它就会停止闪烁。
我创建了一个测试项目,它没有这个问题,即使我复制并粘贴了上面的代码。我不知道有什么不同。
使用定时器怎么样?
var timer: Timer!
func foo {
timer = Timer.scheduledTimer(timeInterval: 1.0,
target: self,
selector: #selector(self.update),
userInfo: nil,
repeats: true)
timer.fire()
}
func update(tm: Timer) {
for annotation in self.mapView.annotations {
if annotation is MKUserLocation { continue }
if let annotationView = mapView.view(for: annotation) {
annotationView.isHidden = !annotationView.isHidden
}
}
}
别忘了停止计时器。
timer.invalidate()
联系苹果开发者支持后,他们告诉我这是一个错误,不是我的代码造成的。
Apple 已表示要删除和添加礼仪以找出破坏它的地方,或者使用他们修复错误的最新版本 Xcode。下载最新版本 Xcode 解决了我的问题。