高德地图 自定义大头针

#import <MAMapKit/MAMapKit.h>

#import "MLFoundCarModel.h"

@protocol MLCustomerAnnotationviewDelegate<NSObject>

-(void)clickAnnotionView:(NSString * )ID subtitle:(NSString *)subtitle;//点击大头针  操作

@end

@interface MLCustomAnnotationView : MAAnnotationView

@property (nonatomic, copy) NSString *name;

@property (nonatomic, strong) UIImage *portrait;

@property (nonatomic, strong) UIView *calloutView;

@property (nonatomic,weak)id<MLCustomerAnnotationviewDelegate>delegate;

@property (nonatomic, strong) UIView *titleView;

@property (nonatomic, strong) UILabel *titles;

@property (nonatomic, strong) NSMutableArray *countArray;

@property (nonatomic, strong) NSMutableArray *datasArr;

 

 

#import "MLCustomAnnotationView.h"

 

 

#define kWidth  84/2

#define kHeight 53+15

 

#define kHoriMargin 5.f

#define kVertMargin 5.f

 

#define kPortraitWidth  50.f

#define kPortraitHeight 50.f

 

#define kCalloutWidth   200.0

#define kCalloutHeight  70.0

 

@interface MLCustomAnnotationView ()

 

@property (nonatomic, strong) UIImageView *portraitImageView;

@property (nonatomic, strong) UILabel *nameLabel;

 

@end

 

@implementation MLCustomAnnotationView

 

@synthesize calloutView;

@synthesize portraitImageView   = _portraitImageView;

@synthesize nameLabel           = _nameLabel;

 

#pragma mark - Handle Action

 

- (void)btnAction

{

    CLLocationCoordinate2D coorinate = [self.annotation coordinate];

    

    NSLog(@"coordinate = {%f, %f}", coorinate.latitude, coorinate.longitude);

}

 

#pragma mark - Override

 

- (NSString *)name

{

    return self.nameLabel.text;

}

 

- (void)setName:(NSString *)name

{

    self.nameLabel.text = name;

}

 

- (UIImage *)portrait

{

    return self.portraitImageView.image;

}

 

- (void)setPortrait:(UIImage *)portrait

{

    self.portraitImageView.image = portrait;

}

 

- (void)setSelected:(BOOL)selected

{

    [self setSelected:selected animated:NO];

}

-(void)setCountArray:(NSMutableArray *)countArray{

    _countArray = countArray;

    

}

 

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

{

    BOOL inside = [super pointInside:point withEvent:event];

    /* Points that lie outside the receiver’s bounds are never reported as hits,

     even if they actually lie within one of the receiver’s subviews.

     This can occur if the current view’s clipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds.

     */

    if (!inside && self.selected)

    {

        inside = [self.calloutView pointInside:[self convertPoint:point toView:self.calloutView] withEvent:event];

    }

    

    return inside;

}

 

#pragma mark - Life Cycle

 

- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier

{

    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];

    

    if (self)

    {

        self.bounds = CGRectMake(0.f, 0.f, kWidth, kHeight);

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickanimoter:)];

        tap.view.tag = self.zIndex;

        [self addGestureRecognizer:tap];

        self.backgroundColor = [UIColor clearColor];

        [self setlayout];

        NSLog(@"sub == %@",self.annotation.subtitle);

    }

    

    return self;

}

-(void)clickanimoter:(UITapGestureRecognizer *)sender{

    if(_delegate && [_delegate respondsToSelector:@selector(clickAnnotionView:subtitle:)]){

        [_delegate clickAnnotionView:self.annotation.title subtitle:self.annotation.subtitle];

    }

}

#pragma mark 布局

-(void)setlayout{

    WS(weakself);

    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.offset(0);

        make.centerX.mas_equalTo(weakself.mas_centerX);

        make.size.mas_equalTo(CGSizeMake(36, 15));

    }];

    [self.titles mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.right.top.bottom.offset(0);

    }];

    [self.portraitImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(weakself.mas_centerX);

        make.top.equalTo(weakself.titleView.mas_bottom).offset(3);

        make.size.mas_equalTo(CGSizeMake(84/2, 105/2));

        make.bottom.offset(0);

    }];

}

#pragma mark  懒加载

-(UIView *)titleView{

    if(!_titleView){

        _titleView = [[UIView alloc]init];

        _titleView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4f];

        _titleView.layer.cornerRadius = 8.0f;

        _titleView.layer.masksToBounds = YES;

        [self addSubview:self.titleView];

    }

    return _titleView;

}

-(UILabel *)titles{

    if(!_titles){

        _titles = [UILabel labelWithText:@"" atColor:White_Color atTextSize:12 atTextFontForType:Common_Font];

        _titles.textAlignment = NSTextAlignmentCenter;

        _titles.font = [UIFont fontWithName:@"Arial" size:11];

        [self.titleView addSubview:self.titles];

    }

    return _titles;

}

-(UIImageView *)portraitImageView{

    if(!_portraitImageView){

        self.portraitImageView = [UIImageView imageViewWithImageName:@""];

        self.portraitImageView.userInteractionEnabled = YES;

         [self addSubview:self.portraitImageView];

    }

    return _portraitImageView;

}

转载于:https://www.cnblogs.com/liaolijun/p/7797768.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值