ios地图sdk提供从天而降动画,仅bmkpinannotationview及继承bmkpinannotationview的子类支持此动画。
显示动画
需要显示此动画效果,只需将bmkpinannotationview的animatesdrop属性设置为yes,代码如下:
//设置从天而降的动画效果annotationview.animatesdrop=yes;
运行程序
效果如下:
利用ios系统uiimageview提供的animationimages来实现帧动画,同时需要自定义bmkannotationview来实现点标记的帧动画。
#import<uikit/uikit.h>@interfaceanimationannotationview: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 =[superinitwithannotation: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
//初始化标注类bmkpointannotation的实例bmkpointannotation*annotation =[[bmkpointannotation alloc] init];//设置标注的经纬度坐标annotation.coordinate=cllocationcoordinate2dmake(39.915,116.404);/**向地图窗口添加标注,需要实现bmkmapviewdelegate的-mapview:viewforannotation:方法来生成标注对应的view@param annotation 要添加的标注*/[_mapview addannotation:annotation];
#pragma mark -bmkmapviewdelegate/**根据anntation生成对应的annotationview@param mapview 地图view@param annotation 指定的标注@return 生成的标注view*/-(bmkannotationview*)mapview:(bmkmapview*)mapview viewforannotation:(id <bmkannotation>)annotation {//动画annotationnsstring*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;}
效果如下:
上一篇
下一篇
本篇文章对您是否有帮助?