移至Xcode 6后,iOS MkMapView为空白 [英] iOS MkMapView blank after moving to Xcode 6

查看:95
本文介绍了移至Xcode 6后,iOS MkMapView为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Xcode 5中创建的mkMapView运行良好的应用程序.最近在Xcode 6.1中创建了一个新应用,并将旧的故事板场景和视图控制器拖到了新应用中.现在,地图视图显示空白屏幕,在IOS 7上没有注释,但在IOS 8上可以使用.我添加了一个按钮,现在地图视图在IOS 8上也为空白.我通过从对象模板中拖动来删除并重新创建情节提要中的视图,并在视图控制器内部的视图内创建了一个地图视图.地图仍然是空白的.调试后,我看到regionWillChangeAnimated和regionDidChangeAnimated重复显示了setRegion事件,这些事件将区域设置为0.0坐标(在设置正确区域之前和之后).

I have apps created in Xcode 5 with mkMapView working well. Recently created a new app in Xcode 6.1 and dragged old storyboard scenes and view controllers to the new app. The map view now shows a blank screen and no annotations on IOS 7 but worked on IOS 8. I added a button and now the map view is blank on IOS 8 as well. I deleted and recreated the view in storyboard with a map view inside a view inside a view controller by dragging from object templates. The map was still blank. After debugging I see that regionWillChangeAnimated and regionDidChangeAnimated show repeated setRegion events that set the region to 0.0 coordinates (before and after I set the correct region).

最后从情节提要视图中删除了mkMapView并使用代码创建了它.

Finally removed the mkMapView from the storyboard view and created it using code.

//Create the map view
_mkMapView = [[MKMapView alloc] initWithFrame:self.view.frame];
_mkMapView.mapType = MKMapTypeSatellite;
_mkMapView.delegate = self;
[self.view addSubview:_mkMapView];
[self.view  setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
self.view.alpha = 1.0;
_mkMapView.mapType = MKMapTypeStandard;
_mkMapView.pitchEnabled = NO;
//Set me as map delegate
_mkMapView.delegate = self;

零setRegion事件现在不会出现&地图工作正常.我应该在情节提要中设置一些内容吗?为什么故事板创建的视图会导致零坐标重复发生setRegion事件?

The zero setRegion events now do not appear & map works OK. Is there something in the storyboard I should be setting? Why would a storyboard created view be causing repeated setRegion events with zero coordinates?

推荐答案

在情节提要中创建地图视图时,听起来像是约束方面的问题.您没有大小限制,因此地图的大小为零,因此区域的大小为零.

It sounds like a problem with your constraints when you were creating the map view in the storyboard. You had no size constraints so the map was zero size so the region was zero size.

该地图从未空白";它完全丢失了.约束不足(模棱两可)的对象无法绘制.这是 ever 成功的一次机会;不幸的是,模棱两可的约束不会导致错误消息,有时运行时实际上会以导致视图出现的方式解决歧义,因此您认为一切正常.最终,麻烦暴露了.

The map was never "blank"; it was missing entirely. An object with insufficient (ambiguous) constraints cannot be drawn. It is just chance that this ever worked; unfortunately, ambiguous constraints do not cause an error message, and sometimes the runtime will actually resolve the ambiguity in a way that causes the view to appear, so you thought everything was okay when it wasn't. Eventually the trouble was exposed.

这篇关于移至Xcode 6后,iOS MkMapView为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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