【问题标题】:In xcode 9 with iOS 11 - issue with loading of Map tiles on first run在带有 iOS 11 的 xcode 9 中 - 首次运行时加载地图图块的问题
【发布时间】:2018-02-13 10:55:31
【问题描述】:

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

mapViewDidFinishLoadingMap 未被调用。因此,地图无法完成时出了点问题,但我没有收到任何错误。

如果我只是短暂退出应用程序然后再次进入,则地图加载正常。这意味着如果从后台打开应用程序,则会加载地图。

任何想法发生了什么变化?在 iOS 10 中运行良好。

更新

在 iOS 11 中,mapViewWillStartLocatingUser 被调用,而不是 mapViewWillStartRenderingMap。我想知道我是否必须手动调用某些东西才能开始渲染地图。在 iOS 9 中(我测试的对象,它是否正常工作)mapViewWillStartRenderingMapmapViewWillStartLocatingUser 之前被调用

【问题讨论】:

  • 您是否在视图控制器的 viewDidLoad 方法中初始化 MapView?如果是这样,请尝试将其移至 viewDidAppear 方法。
  • @KosukeOgawa 刚试过,但没什么区别。也不是我想要的,因为这会破坏可用性,因为地图会经常重新加载。
  • 现在我正在等待它是否会在以后的 beta 版本中得到解决。否则我会回去尝试寻找解决方案。
  • 不幸的是,这在新的 xcode 版本中仍然是一个问题。 @onmyway133 你找到解决方案了吗?
  • 曾经调用过 mapViewWillStartLoadingMap 或 mapViewDidFailLoadingMap 吗?

标签: ios mapkit ios11


【解决方案1】:

我认为你应该尝试删除

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

}

并将以下代码放入您的 View Didload 方法中

    CGFloat edge = 10.0f;

    UIImage *gotoUserLocationButtonImage = self.gotoUserLocationButton.imageView.image;
    self.gotoUserLocationButton.frame = CGRectMake(edge, edge + self.statusBarHeight, gotoUserLocationButtonImage.size.width, gotoUserLocationButtonImage.size.height);

    UIImage *getDirectionsButtonImage = self.getDirectionsButton.imageView.image;
    [self.getDirectionsButton setFrame:CGRectMake(CGRectGetMaxX(self.gotoUserLocationButton.frame), edge + self.statusBarHeight, getDirectionsButtonImage.size.width, getDirectionsButtonImage.size.height)];

【讨论】:

  • 不确定你的意思。用户位置有效,也显示在“地图”上。如上图所示。你是这个意思吗?
  • 哦,对不起。您能否尝试在 viewWillAppear 中重新加载地图。因为显然它看起来没有问题。
  • 给我一点时间,我正在演示中尝试。
  • 我无法在演示中运行它,因为有大量的依赖代码。不幸的是,但我正在尝试找到问题,我会与您分享。
  • 是的,很抱歉。这是一个复杂的项目:/我尝试使用“[self.mapView setRegion:self.mapView.region animated:true];”重新加载地图在 viewWillAppear 和 viewDidAppear 中。但什么也没做。
【解决方案2】:

确保您没有对地图使用 dispatch_async。

我有以下在iOS11中不起作用的功能

dispatch_async(dispatch_get_main_queue(), ^{
    @synchronized(_queue) {
        if(poppedMapView != nil) {
            [self.queue removeObject:poppedMapView];
        }
        [self.queue addObject:[[MKMapView alloc] init]];
    }
});

改成

if(poppedMapView != nil) {
    [self.queue removeObject:poppedMapView];
}
[self.queue addObject:[[MKMapView alloc] init]];

【讨论】:

    【解决方案3】:

    我遇到了完全相同的问题,花了很多时间寻找解决方案,最后我做到了。所以在我的情况下,问题是错误的初始化。通常你会在 viewController 的顶部写 let mapView = MKMapView() ,然后稍后在 viewDidLoad 的某个地方对其进行自定义,但是在 IOS 11 Beta 1 之后它停止工作。我通过更改为 var mapView: MKMapView?在 viewController 的顶部,然后在 viewDidLoad 内部,我像 mapView = MKMapView() 一样初始化它。希望它可以帮助某人! :)

    【讨论】:

      【解决方案4】:

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

      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 更改为:

      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 方法中,但这对我不起作用:

      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()
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多