Mapbox动画用户位置更加流畅

时间:2015-08-15 13:07:59

标签: ios swift mapkit mapbox

我正在使用Mapbox并像这样实例化:

import MapboxGL


class RideViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, MGLMapViewDelegate{
    @IBOutlet weak var mapViewWrapper: UIView!
    var mapView: MGLMapView!

    override func viewDidLoad(){
        // Location manager
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()
        locationManager.activityType = .Fitness

        // Mapbox
        mapView = MGLMapView(frame: mapViewWrapper.bounds, styleURL: NSURL(string: Mapbox.getTheme()))
        mapView.autoresizingMask = .FlexibleWidth | .FlexibleHeight
    mapView.userTrackingMode = .Follow
    mapView.showsUserLocation = true
    mapView.scrollEnabled = false
    mapView.rotateEnabled = false
    mapView.logoView.hidden = true
    mapView.attributionButton.hidden = true
        // set the map's center coordinate
        mapView.setCenterCoordinate(appleMap.userLocation.coordinate,
            zoomLevel: 12, animated: true)
        mapViewWrapper.addSubview(mapView)

    }

    func locationManager(manager:CLLocationManager, didUpdateLocations locations:[AnyObject]) {
        myLocations.append(locations[0] as! CLLocation)                      
        mapView.setCenterCoordinate(appleMap.userLocation.coordinate, zoomLevel: 16, animated: true)                                                    
    }

}

正如你所看到的那样animated: true但是它非常紧张,任何想法我做错了什么?

1 个答案:

答案 0 :(得分:0)

在整个UIview生命周期方法中分发您的locationManagermapView方法,例如viewWillAppearviewDidAppear等。

它应该给系统更多的时间来容纳初始化,而不是一次性抛出所有请求。

详情请访问:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/viewDidAppear