问题描述
当用户平移或缩放地图时,我需要根据对MKMapView的更改重绘一些UI。
I have some UI that I need to redraw based on changes to an MKMapView when the user pans or zooms the map.
目前我正在使用移动事件手势识别器和MKMapViewDelegate regionDidChangeAnimated消息重绘我的依赖UI。这是我需要的90%。
Currently I am using a move event gesture recogniser and MKMapViewDelegate regionDidChangeAnimated messages to redraw my dependant UI. This is 90% of what I need.
我缺少的事件是用户抬起手指(不再有移动事件)到MKMapViewDelegate regionDidChangeAnimated消息的时间点被解雇了。在此期间,地图缓慢停止,我的依赖用户界面停留在不同步的地图图块内容中。
The events I am missing are from the point the user lifts their finger (no more move events) to when the MKMapViewDelegate regionDidChangeAnimated message is fired. During that period the map slowly pans to a halt and my dependant UI is stuck with map tile content that is out of synch.
是否有较低级别的API会通知我重新绘制UIView(在本例中为MKMapView)内容?
Is there a lower level API that will notify me when UIView (in this case MKMapView) content is redrawn?
更新
我尝试创建一个代理MKMapView子类,它将drawRect调用转发到我提供的委托。我得到了第一个抽奖活动,但后来都没有,所以这对我的困境没有帮助。
I tried creating a proxy MKMapView subclass that forwarded drawRect calls onto my supplied delegate. I get the first draw event but none of the subsequent ones, so this doesn't help with my predicament.
推荐答案
IIRC,不幸的是,MKMapView @ 区域
。
IIRC, MKMapView is unfortunately not KVO-compliant for @"region"
.
您可能会在 regionWillChangeAnimated $ c $中设置
NSTimer
c>,使用它在滚动/平移/等等过程中刷新UI,并在 regionDidChangeAnimated
中丢弃它。虽然不太优雅,如果你需要非常快,它可能不适合你的需求。
You might hack you way setting up an NSTimer
in regionWillChangeAnimated
, using it to refresh you UI during the scroll/pan/etc, and discarding it in regionDidChangeAnimated
. Not quite elegant though, and it may not suit your needs if you need to be really fast.
或者,你可以寻找 UIScrollView
在MKMapView的子视图中,并观察其转换
。
Alternatively, you may look for the UIScrollView
in MKMapView's subviews, and observe its transform
.
(我没有测试任何这些。)
(I haven't tested any of these.)
无论如何,我怀疑监视 MKMapView
上的重绘事件是否有用: MKMapView
使用 CATiledLayer
异步执行绘图,因此您甚至无法确定何时已经完成。
In any case, I doubt that monitoring redraw events on a MKMapView
will be of any use : MKMapView
uses CATiledLayer
to perform its drawing asynchronously, so you can't even be sure when it's done.
编辑:这显然不适用于iOS 6.当然,这不应该真的来令人惊讶。但是,据我所知,委托方法的行为相同,因此OP的问题仍然存在。我没有找到更新的解决方案。
Edit : This apparently does not work with iOS 6. Of course, this should not really come as a surprise. However, as far as I know, the delegate methods behave the same, so the OP's problem is still real. I haven't looked for an updated solution.
这篇关于监视MKMapView重绘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!