MapView检测滚动 [英] MapView detect scrolling

查看:73
本文介绍了MapView检测滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望MKMapView是从UIScrollView继承的,就像UITableViewUICollectionView一样.这样,您可以覆盖UIScrollView委托方法并执行所需的操作.

I'm wishing that MKMapView inherited from UIScrollView just like UITableView and UICollectionView are. This way you can override the UIScrollView delegate methods and do what you need to do.

我发现了将摇摄手势附加到MapView的方法,如下所示:

I've found the method of attaching a pan gesture to the MapView like so:

UIPanGestureRecognizer* mapPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mapPanGestureHandler:)];
[mapPanGestureRecognizer setDelegate:self];
[self.mapView addGestureRecognizer:mapPanGestureRecognizer];

除了mapView具有减速度元素这一事实外,此方法效果很好.例如,如果您处于中间滚动状态并抬起手指,则地图会继续前进并放慢速度,然后最终停止.

This works fairly well except for the fact that the mapView has a deceleration element to it. For example if you're in mid scroll and lift your finger, the map keeps going and slows down then eventually stops.

我正在做的是使用核心图形在地图顶部的覆盖层(另一个UIView)中渲染一些屏幕外注释.除减速问题外,它的工作效果非常好.

What I'm doing is rendering some offscreen annotations in an overlay on top of my map (another UIView) using core graphics. It's working great except for the deceleration problem.

我只需要知道地图已经移动.我需要的参数可以直接从地图本身查询.

All I need to know is that the map has moved. The parameters I need I can query straight from the map itself.

有没有人发现一种在减速时获取回调的技术?我的意思是我想我可以在手势结束重复发射半秒左右时使用计时器.

Has anyone found a technique to get callbacks while decelerating? I mean I suppose I could use a timer when the gesture ends to fire repeatedly for a half a second or so.

推荐答案

MKMapView没有与UIScrollView相似的委托回调,因此您需要即兴创作.

MKMapView doesn't have analogous delegate callback to UIScrollView, so you're going to need to improvise.

有没有人发现一种在减速时获取回调的技术?我的意思是我想我可以在手势结束重复发射半秒左右时使用计时器.

Has anyone found a technique to get callbacks while decelerating? I mean I suppose I could use a timer when the gesture ends to fire repeatedly for a half a second or so.

如果您想准确地使视图与地图的运动保持同步,则最好使用CADisplayLink,因为每次刷新屏幕后都会得到回调.另一方面,如果使用计时器,则回调不一定与刷新率保持一致,并且可能会看到瑕疵.

If you're wanting to accurately keep views in sync with the map's movement, you'll be better off using CADisplayLink because you'll get a callback after each screen refresh. On the other hand, if you use a timer, the callbacks won't necessarily align with the refresh rate and you may see artifacts.

您可以这样设置:

CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateViewsBasedOnMapRegion:)];
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

然后像这样处理回调:

- (void)updateViewsBasedOnMapRegion:(CADisplayLink *)link
{
    // update whatever it is you need to update
}

您可以专门使用它并丢弃手势识别器,或者保留手势识别器并在不需要时暂停链接.

You could use this exclusively and discard the gesture recognizer or keep the gesture recognizer and pause the link when not needed.

这篇关于MapView检测滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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