swift - Swift 4 mapkit 在隐藏地图注释后重新加载地图
问题描述
我有两个视图控制器,它们显示一个 mapkit,一个用于具有后退按钮的位置描述。但是每次我尝试隐藏地图注释并转到地点描述然后再次返回到 mapkit 时,它都会使用我尝试隐藏的注释重新加载我的地图。如何防止 mapkit 重新加载其数据但仍隐藏我的地图注释?
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
//1
let coordinate = view.annotation!.coordinate
//2
if let userCoordinate = userLocation {
//3
if userCoordinate.distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)) < 30000 {
//4
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let viewController = storyboard.instantiateViewController(withIdentifier: "ARViewController") as? PlaceViewController {
// more code later
//5
if let mapAnnotation = view.annotation as? MapA {
//6
if(mapAnnotation.title == "New")
{
mapView.view(for: mapAnnotation)?.isHidden = true
self.present(viewController, animated: true, completion: nil)
viewController.adL.text = "TEST"
viewController.descT.text = "Hej"
}
}
解决方案
它重新加载,因为这里
mapView.view(for: mapAnnotation)?.isHidden = true
您明确调用它来重新加载
你可以直接做
view.isHidden = true
当你看到这里的景色
didSelect view: MKAnnotationView
当前选择的
推荐阅读
- angular - 将来自 Angular 应用程序的请求发布到 firebase 数据库
- python - Python Plotly 图形与辅助 x 轴链接到主要
- mysql - Supertest 中的 MySQL 查询返回 {sql, bindings} 而不是结果
- java - 当一个线程执行java.lang.Class.getDeclaredMethods0时,其他线程被锁定
- javascript - 使用 forEach 循环构建 html 表和日期/时间作为 null
- python - 标准化 get_success_url
- reactjs - 实现 React DnD 后在 React 中刷新子组件
- android - 使用条件语句刷新 Webview
- qt - QML - GridLayout - ROW 和 COLUMN Span - 理解
- c# - 带有 GenericRepository 错误的依赖注入 - 没有为此 DbContext NET.Core 3.1 配置数据库提供程序