浏览器版本低!无法浏览完整内容,建议升级或更换浏览器。
点标记动画
下载开发文档
从天而降动画

iOS地图SDK提供从天而降动画,仅BMKPinAnnotationView及继承BMKPinAnnotationView的子类支持此动画。

显示动画

需要显示此动画效果,只需将BMKPinAnnotationView的animatesDrop属性设置为YES,代码如下:

//设置从天而降的动画效果
annotationView.animatesDrop = YES;

运行程序

效果如下:

帧动画

利用iOS系统UIImageView提供的animationImages来实现帧动画,同时需要自定义BMKAnnotationView来实现点标记的帧动画。

1. 自定义AnimatedAnnotationView
#import <UIKit/UIKit.h>
@interface AnimationAnnotationView: BMKAnnotationView
//存储每一帧图片
@property (nonatomic, strong) NSMutableArray *annotationImages;
//展示帧动画的UIImageView
@property (nonatomic, strong) UIImageView *annotationImageView;
@end
#import "AnimationAnnotationView.h"
@implementation AnimationAnnotationView
- (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
[self setBounds:CGRectMake(0.f, 0.f, 32.f, 32.f)];
[self setBackgroundColor:[UIColor clearColor]];
_annotationImageView = [[UIImageView alloc] initWithFrame:self.bounds];
_annotationImageView.contentMode = UIViewContentModeCenter;
[self addSubview:_annotationImageView];
}
return self;
}
- (void)setAnnotationImages:(NSMutableArray *)images {
_annotationImages = images;
[self updateImageView];
}
- (void)updateImageView {
if ([_annotationImageView isAnimating]) {
[_annotationImageView stopAnimating];
}
_annotationImageView.animationImages = _annotationImages;
_annotationImageView.animationDuration = 0.5 * [_annotationImages count];
_annotationImageView.animationRepeatCount = 0;
[_annotationImageView startAnimating];
}
@end
2. 添加点标记
//初始化标注类BMKPointAnnotation的实例
BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];
//设置标注的经纬度坐标
annotation.coordinate = CLLocationCoordinate2DMake(39.915, 116.404);
/**
向地图窗口添加标注,需要实现BMKMapViewDelegate的-mapView:viewForAnnotation:方法
来生成标注对应的View
@param annotation 要添加的标注
*/
[_mapView addAnnotation:annotation];
3. 实现代理方法返回AnimatedAnnotationView
#pragma mark - BMKMapViewDelegate
/**
根据anntation生成对应的annotationView
@param mapView 地图View
@param annotation 指定的标注
@return 生成的标注View
*/
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation {
//动画annotation
NSString *AnnotationViewID = @"AnimatedAnnotation";
AnimationAnnotationView *annotationView = nil;
if (annotationView == nil) {
annotationView = [[AnimationAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID];
}
NSMutableArray *images = [NSMutableArray array];
for (int i = 1; i < 4; i++) {
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"poi-%d.png", i]];
[images addObject:image];
}
annotationView.annotationImages = images;
return annotationView;
}
4. 运行程序

效果如下:

上一篇

绘制弧线和面

下一篇

点聚合

本篇文章对您是否有帮助?