在带有iOS 11的xcode 9中 - 首次运行时加载地图图块的问题 [英] In xcode 9 with iOS 11 - issue with loading of Map tiles on first run

查看:127
本文介绍了在带有iOS 11的xcode 9中 - 首次运行时加载地图图块的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 更新了新发现 - 在模拟器和设备上进行了测试。从冷启动运行应用程序时,无法正确加载地图。未显示平铺。

--Updated with new findings -- Tested in both simulator and on device. Maps are not loaded correctly when the app is run from a cold start. Tiles are not being displayed.

mapViewDidFinishLoadingMap 未被调用。所以地图没有完成会出错,但我没有错误。

mapViewDidFinishLoadingMap is not being called. So something is going wrong for the map not to finish, but I am getting no errors.

如果我只是简单地退出应用程序,那么地图就可以正常加载再次。这意味着如果从后台打开应用程序,则会加载地图。

The map is loaded fine if I just briefly go out of the app and then in again. Meaning that the maps are loaded if app is opened from background.

任何想法有什么变化?在iOS 10中运行得很好。

Any ideas what has change? Worked just fine in iOS 10.

< img src =https://i.stack.imgur.com/KSpObm.pngalt =在此处输入图像说明>

更新

在iOS 11中正在调用mapViewWillStartLocatingUser 但不是 mapViewWillStartRenderingMap 。我想知道是否必须手动调用某些内容,以便启动地图渲染。在iOS 9中(我测试的是,它运行得很好) mapViewWillStartRenderingMap mapViewWillStartLocatingUser

In iOS 11 mapViewWillStartLocatingUser is being called but not mapViewWillStartRenderingMap. I wondering if I have to manual call something so that the rendering off the map will be started. In iOS 9 (what I test against, and were it works just fine) mapViewWillStartRenderingMap is called before mapViewWillStartLocatingUser

推荐答案

同样的问题我的BROKEN代码看起来像:

Had same problem my BROKEN code looked something like:

class ViewController: UIViewController {

    fileprivate var mapView = MKMapView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Add the mapView to the VC
        mapView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(mapView)
        mapView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        mapView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
        mapView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
    }
}

正如在iOS 11中发现的那样,它不喜欢在视图控制器加载之前初始化MKMapView,即viewDidLoad()所以FIX正在变为:

As it turned out in iOS 11 it does not like having the MKMapView initialize before the view controller has loaded ie viewDidLoad() so FIX was changing to:

class ViewController: UIViewController {

    fileprivate var mapView: CSMapView?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Init instance here.
        mapView = CSMapView()

        // Add the mapView to the VC
        mapView?.translatesAutoresizingMaskIntoConstraints = false
        ...
    }
}

还尝试将它放在init方法中,但这对我不起作用:

Also tried putting it in init methods but this DID NOT work for me:

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    mapView = MKMapView()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    mapView = MKMapView()
}

这篇关于在带有iOS 11的xcode 9中 - 首次运行时加载地图图块的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆