当我把它放在标签栏时,MapKit是黑色的

时间:2017-03-02 13:50:45

标签: ios swift

我想要标签栏中的地图页面,但是当我运行应用程序时,地图显示为黑色页面! 然而,当我在第一个视图中放置地图时它显示正常,我不知道当我将它移动到标签栏控制器时它变成黑色的原因! ,我的Xcode版本是8.2.1,带有swift 3,这是我的代码:

import UIKit
import MapKit
import CoreLocation


class MapPage: UIViewController , CLLocationManagerDelegate {

    @IBOutlet weak var map: MKMapView!



    let manager = CLLocationManager()

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let location = locations[0]
        let span:MKCoordinateSpan = MKCoordinateSpanMake(0.01,0.01)
        let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
        let region:MKCoordinateRegion = MKCoordinateRegionMake(myLocation, span)
        map.setRegion(region, animated: true)

        print(location.altitude)
        print(location.speed)

        self.map.showsUserLocation = true

    }

    override func viewDidLoad() {
        super.viewDidLoad()
        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestWhenInUseAuthorization()
        manager.startUpdatingLocation()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


}

this is the first view when i run it

here is when i put the map in the tab bar view

0 个答案:

没有答案