自2018年10月18日起,高德开发者论坛除车机板块外,其他板块将停止发帖与维护,如您有使用问题请 提交工单 联系我们,感谢您的理解。

查看: 384|回复: 3
打印 上一主题 下一主题

[应用案例] 怎么重写大头针点击事件的方法?

[复制链接]
最佳答案
0 

1

主题

4

帖子

11

积分

新手上路

Rank: 1

积分
11
跳转到指定楼层
楼主
发表于 2018-1-15 17:14:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
发表帖子
API/SDK版本号: AMap2DMap
产品: 2D地图
手机型号: iPhone
使用接口: http
本帖最后由 fox_ice 于 2018-1-15 17:16 编辑

- (MAAnnotationView *)mapViewMAMapView *)mapView viewForAnnotationid <MAAnnotation>)annotation
{
    // 自定义坐标
    CurrentLocationAnnotation * current  = (CurrentLocationAnnotation *)annotation;
    if ([annotation isKindOfClass:[CurrentLocationAnnotation class]])
    {
        static NSString *reuseIndetifier = @"CustomAnnotationView";
        MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        else
        {
            while ([annotationView.subviews lastObject] != nil)
            {
                [(UIView*)[annotationView.subviews lastObject] removeFromSuperview];
            }
        }

        UIButton *btn = [UIFactory initBorderButtonWithFrame:CGRectMake(0,0, 100, 40) title:[NSString stringWithFormat"%@\n%@",[annotation title],[annotation subtitle]] textColor:[UIColor whiteColor] font:systemOfFont(13) cornerRadius:10 bgColor:kNavBarTintColor borderColor:[UIColor groupTableViewBackgroundColor] borderWidth:0.5 tag:current.index target:self actionselector(btnAction];
        btn.titleLabel.numberOfLines = 2;
        annotationView.enabled = YES;
        annotationView.userInteractionEnabled = YES;
        [annotationView addSubview:btn];

        //annotationView.image = [UIImage imageNamed"mapAddress"];
        // 设置为NO,用以调用自定义的calloutView
        annotationView.canShowCallout = false;
        // 设置中心点偏移,使得标注底部中间点成为经纬度对应点
        annotationView.centerOffset = CGPointMake(0, -18);
        return annotationView;
    }
    return nil;
}

回复

使用道具 举报

最佳答案
0 

1

主题

4

帖子

11

积分

新手上路

Rank: 1

积分
11
沙发
 楼主| 发表于 2018-1-15 17:14:46 | 只看该作者
- (void)btnActionUIButton *)sender
{
    for (MAAnnotationView * view in self.mapView.subviews) {
        if (view.tag == sender.tag) {
            [self mapView:self.mapView didSelectAnnotationView:view];
        }
    }
}
回复 支持 反对

使用道具 举报

最佳答案
0 

1

主题

4

帖子

11

积分

新手上路

Rank: 1

积分
11
板凳
 楼主| 发表于 2018-1-15 17:15:25 | 只看该作者
为毛按钮事件不会走,应该怎么重写
回复 支持 反对

使用道具 举报

最佳答案
0 

1

主题

4

帖子

11

积分

新手上路

Rank: 1

积分
11
地板
 楼主| 发表于 2018-1-15 17:15:48 | 只看该作者
- (MAAnnotationView *)mapViewMAMapView *)mapView viewForAnnotationid <MAAnnotation>)annotation
{
    // 自定义坐标
    CurrentLocationAnnotation * current  = (CurrentLocationAnnotation *)annotation;
    if ([annotation isKindOfClass:[CurrentLocationAnnotation class]])
    {
        static NSString *reuseIndetifier = @"CustomAnnotationView";
        MAAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:reuseIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[MAAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIndetifier];
        }
        else
        {
            while ([annotationView.subviews lastObject] != nil)
            {
                [(UIView*)[annotationView.subviews lastObject] removeFromSuperview];
            }
        }
        
        UIButton *btn = [UIFactory initBorderButtonWithFrame:CGRectMake(0,0, 100, 40) title:[NSString stringWithFormat"%@\n%@",[annotation title],[annotation subtitle]] textColor:[UIColor whiteColor] font:systemOfFont(13) cornerRadius:10 bgColor:kNavBarTintColor borderColor:[UIColor groupTableViewBackgroundColor] borderWidth:0.5 tag:current.index target:self actionselector(btnAction];
        btn.titleLabel.numberOfLines = 2;
        annotationView.enabled = YES;
        annotationView.userInteractionEnabled = YES;
        [annotationView addSubview:btn];
        
        //annotationView.image = [UIImage imageNamed"mapAddress"];
        // 设置为NO,用以调用自定义的calloutView
        annotationView.canShowCallout = false;
        // 设置中心点偏移,使得标注底部中间点成为经纬度对应点
        annotationView.centerOffset = CGPointMake(0, -18);
        return annotationView;
    }
    return nil;
}

//大头针点击事件重写
- (void)btnActionUIButton *)sender
{
    for (MAAnnotationView * view in self.mapView.subviews) {
        if (view.tag == sender.tag) {
            [self mapView:self.mapView didSelectAnnotationView:view];
        }
    }
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|小黑屋|高德开发者论坛

Copyright ©2014 高德开发者论坛.All Rights Reserved |京ICP证070711号

意见反馈 常见问题 服务条款 联系我们
快速回复 返回顶部 返回列表