gpt4 book ai didi

ios - 在 UITableViewCell 上时,MKPointAnnotation 在 mapView 上闪烁。如何阻止它?

转载 作者:行者123 更新时间:2023-11-28 07:58:04 25 4
gpt4 key购买 nike

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

我已确保注释只添加到 map 一次。这是它发生的视频https://youtu.be/lkpn9Rqd0AE此外,这只会在没有用户交互时发生,如果我滚动它就会停止,如果我与 map 交互它就会停止闪烁。

我创建了一个测试项目,它没有这个问题,即使我复制并粘贴了上面的代码。我不知道有什么不同。

最佳答案

使用 Timer 怎么样?

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()

关于ios - 在 UITableViewCell 上时,MKPointAnnotation 在 mapView 上闪烁。如何阻止它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47423523/

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