注释不显示

问题描述

进入地图视图控制器后,UITabBarItem必须在将注释添加到地图之后执行操作

MapViewController类:UIViewController,UITabBarDelegate {

@IBOutlet weak var middleMapButton: UITabBarItem!
@IBOutlet weak var mapView: MKMapView!

let locationManager = CLLocationManager()
let regionInMeters: Double = 10000

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationController?.isNavigationBarHidden = true
    ecoMapButton.image = UIImage(systemName: "plus.circle")
}

override func viewWilldisappear(_ animated: Bool) {
    super.viewWilldisappear(animated)
    navigationController?.isNavigationBarHidden = false
    middleMapButton.image = UIImage(systemName: "mappin.circle")
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    checkLocationServices()
    
}

这是该标签栏项目的操作

func tabBar(_ tabBar: UITabBar,didSelect item: UITabBarItem) {
    let annotation = MKPointAnnotation()
    annotation.coordinate = CLLocationCoordinate2D(latitude: 41.881832,longitude: -87.623177)
    mapView.addAnnotation(annotation)
}

这里有一些位置隐私行动

func setupLocationManager() {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
}

func centerViewOnUserLocation() {
    if let location = locationManager.location?.coordinate {
        let region = MKCoordinateRegion.init(center: location,latitudinalMeters: regionInMeters,longitudinalMeters: regionInMeters)
        mapView.setRegion(region,animated: true)
    }
}

func checkLocationServices() {
    if CLLocationManager.locationServicesEnabled() {
        setupLocationManager()
        checkLocationAuthorization()
    } else {
        
    }
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)