由于最近的项目有用到百度地图的地方,要求修改百度地图的定位图标,并且实现动画.
下面直接贴码
- (void)viewDidLoad
{
[super viewDidLoad];
//调用实现定位图标修改的方法,在此之前需要获取到定位地址的经纬度
[self loadAnnotion];
}
-(void)loadAnnotion{
static dispatch_once_t addLocation; //只执行一次
dispatch_once(&addLocation, ^{
BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc]init];
annotation.coordinate = self.coor; //self.coor为获取到的定位地址经纬度
[_mapView addAnnotation:annotation];
});
}
// 根据anntation生成对应的View
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id)annotation
{
NSString *ID = @"annotion";
BMKPinAnnotationView *annotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ID];
if (annotationView == nil) {
annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ID];
annotationView.image = [UIImage imageNamed:@"locationback"];//此处的图片为一张白色的背景图
annotationView.size = CGSizeMake(30, 30); //设置大小
annotationView.layer.cornerRadius = 15; // 设置为圆形的视图
annotationView.layer.masksToBounds = YES;
// 在此处,为圆形的背景上添加一个小红点
UIView *redDots = [[UIView alloc]init];
redDots.frame = CGRectMake(7.5, 7.5, 15, 15);
redDots.backgroundColor = [UIColor redColor];
redDots.layer.cornerRadius = 7.5;
[annotationView addSubview:redDots];
//实现动画
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 3.0;// 动画时间
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.7, 0.7, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.3, 1.3, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.7, 0.7, 1.0)]];
animation.values = values;
animation.repeatCount = FLT_MAX;
[redDots.layer addAnimation:animation forKey:nil];
}
return annotationView;
}
网友评论