前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ios 百度地图 获取拖动或缩放手势

ios 百度地图 获取拖动或缩放手势

作者头像
赵哥窟
发布2018-10-12 10:10:41
1.5K0
发布2018-10-12 10:10:41
举报
文章被收录于专栏:日常技术分享

在项目中遇到一个问题,在拖动或者缩放百度地图的时候要请求数据。但是百度地图SDK中没有明确如何获取拖动和缩放手势 官方推荐使用如下两个方法,通过判断状态来获取,但是也没有明确怎么判断。还有个问题就是如果在regionDidChangeAnimated请求数据的话,产品还有个需百度地图的中心点以最新一条数据的经纬度移动。只要中心点移动了又会调用regionDidChangeAnimated,这样就会造成多次请求接口。

代码语言:javascript
复制
/**
 *地图区域即将改变时会调用此接口
 *@param mapView 地图View
 *@param animated 是否动画
 */
- (void)mapView:(BMKMapView *)mapView regionWillChangeAnimated:(BOOL)animated;

/**
 *地图区域改变完成后会调用此接口
 *@param mapView 地图View
 *@param animated 是否动画
 */
- (void)mapView:(BMKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;

这里推荐使用自定义手势来判断. 注意:加自定义手势时,必须设置UIGestureRecognizer的属性cancelsTouchesInView 和 delaysTouchesEnded 为NO,否则影响地图内部的手势处理。

代码语言:javascript
复制
 // 拖动
    UIPanGestureRecognizer *mapPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(mapPanGesture:)];
    mapPanGesture.delegate = self;
    mapPanGesture.cancelsTouchesInView = NO;
    mapPanGesture.delaysTouchesEnded = NO;
    [_mapView addGestureRecognizer:mapPanGesture];
    
    // 缩放
    UIPinchGestureRecognizer *mapPinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(mapPinchGesture:)];
    mapPinchGesture.delegate = self;
    mapPinchGesture.cancelsTouchesInView = NO;
    mapPinchGesture.delaysTouchesEnded = NO;
    [_mapView addGestureRecognizer:mapPinchGesture];

/**
 百度地图拖动手势
 
 @param gesture 手势
 */
- (void)mapPanGesture:(UIGestureRecognizer *)gesture
{
    if ([gesture state] == UIGestureRecognizerStateBegan) {
       
    }
}

/**
 百度地图缩放手势
 
 @param gesture 手势
 */
- (void)mapPinchGesture:(UIGestureRecognizer *)gesture
{
    if ([gesture state] == UIGestureRecognizerStateBegan) {
       
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.10.11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档