MKMapView 区域WillChangeAnimated 缩放或平移?
我需要知道是否由于缩放或平移而发生了regionWillChangeAnimated。
通过跟踪旧区域跨度并与新区域跨度进行比较以查看是否发生缩放,我能够为 RegionDidChangeAnimated 找出这一点。
RegionWillChangeAnimated 的问题是它是在区域更改之前调用的,因此我无法知道区域跨度是多少。
也许还有另一种方法可以解决这个问题吗?
谢谢。
I need to know whether a regionWillChangeAnimated occurred due to zooming or panning.
I was able to figure this out for regionDidChangeAnimated by keeping track of the old region span and comparing with the new one to see if a zoom occurred.
The problem with regionWillChangeAnimated is that it is called before the region changes so I have no way to know what the region span will be.
Is there another way perhaps to figure this out?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须将地图的当前跨度与
mapView:regionWillChangeAnimated:
中的前一个跨度进行比较,在缩放或滚动期间会多次调用该跨度。您可以使用 breadcrumb 示例项目中的代码:<代码>MKZoomScale currentZoomScale = (CGFloat)(map.bounds.size.width / map.visibleMapRect.size.width);
You have to compare the current span of the map with the previous one in
mapView:regionWillChangeAnimated:
, which gets called many times during zooming or scrolling.You can use code from the breadcrumb sample project:
MKZoomScale currentZoomScale = (CGFloat)(map.bounds.size.width / map.visibleMapRect.size.width);
我相信您需要在regionWillChangeAnimated调用中获取当前区域跨度和中心数据,并在到达regionDidChangeAnimated调用后对其进行比较,但不要在其中执行太多逻辑,否则可能会使用户交互不稳定。
i believe you will need to get the current region span and center data in the regionWillChangeAnimated call and compare it once you get to the regionDidChangeAnimated call but dont do too much logic in there or it can make the user interaction choppy.
我没有足够的声誉配额来发表评论,但无论如何还是有必要警告一下:您不能仅使用地图的区域跨度来确定是否发生了缩放。对于恒定的缩放级别,地图的水平比例根据纬度而变化。
I don't have the reputation quota to comment, but felt the need to warn anyway: you can't use just the region span of the map to determine if a zoom has occurred. For a constant zoom level, the horizontal scale of the map varies based on latitude.