产品需要等待界面有一个雷达效果,之前做过百度的,新接手需要做高德的,网上找了半天还是自己实现了,其实很简单,直接自定义高德地图定位小蓝点,用GIF替换就有效果.上代码
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
// r.strokeColor = [UIColor blueColor];
// r.fillColor = [UIColor redColor];
// r.lineWidth = 4;
// r.enablePulseAnnimation = YES;
r.showsAccuracyRing = NO;///精度圈是否显示,默认YES
// r.locationDotBgColor = [UIColor whiteColor];
NSString*name = @"tuotuoMapGIF.gif";
NSString *filePath = [[NSBundle bundleWithPath:[[NSBundle mainBundle] bundlePath]] pathForResource:name ofType:nil];
NSData*imageData = [NSDatadataWithContentsOfFile:filePath];
UIImageView*loadingImageView = [[UIImageViewalloc]init];
loadingImageView.backgroundColor= [UIColorclearColor];
r.image= [selfgifChangeToImageWithData:imageData];
//r.frame = CGRectMake(0, 0, 124, 124);
[selfconfigUI:loadingImageView];
[self.mapView updateUserLocationRepresentation:r];
[MapManager manager].mapView = self.mapView;
这里的mapView就是高德地图MAMapView
[selfgifChangeToImageWithData:imageData];
[selfconfigUI:loadingImageView];
上面这两个方法是将从UI拿拿到的GIF转给image.这样实现更便捷,更简单,样式可选性也比较强.
- (UIImage*)gifChangeToImageWithData:(NSData*)data
{
if(!data)
{
returnnil;
}
CGImageSourceRefsource =CGImageSourceCreateWithData((__bridgeCFDataRef)data,NULL);
size_tcount =CGImageSourceGetCount(source);
UIImage*animatedImage;
if(count <=1)
{
animatedImage = [[UIImagealloc]initWithData:data];
}
else
{
NSMutableArray*images = [NSMutableArrayarray];
NSTimeIntervalduration =3.0f;
for(size_ti =0; i < count; i++)
{
CGImageRefimage =CGImageSourceCreateImageAtIndex(source, i,NULL);
if(!image)
{
continue;
}
duration += [selfframeDurationAtIndex:i source:source];
[imagesaddObject:[UIImageimageWithCGImage:image scale:[UIScreenmainScreen].scaleorientation:UIImageOrientationUp]];
CGImageRelease(image);
}
if(!duration)
{
duration = (1.0f/10.0f) * count;
}
animatedImage = [UIImageanimatedImageWithImages:imagesduration:duration];
}
CFRelease(source);
returnanimatedImage;
}
- (void)configUI:(UIImageView*)loadingImageView
{
loadingImageView.center=CGPointMake(400/2,400/2);
loadingImageView.tag=0xadd;
[self.viewaddSubview:loadingImageView];
}
- (float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source
{
floatframeDuration =0.1f;
CFDictionaryRefcfFrameProperties =CGImageSourceCopyPropertiesAtIndex(source, index,nil);
NSDictionary*frameProperties = (__bridgeNSDictionary*)cfFrameProperties;
NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
NSNumber*delayTimeUnclampedProp = gifProperties[(NSString*)kCGImagePropertyGIFUnclampedDelayTime];
if(delayTimeUnclampedProp)
{
frameDuration = [delayTimeUnclampedPropfloatValue];
}
else
{
NSNumber*delayTimeProp = gifProperties[(NSString*)kCGImagePropertyGIFDelayTime];
if(delayTimeProp)
{
frameDuration = [delayTimePropfloatValue];
}
}
if(frameDuration <0.011f)
{
frameDuration =0.100f;
}
CFRelease(cfFrameProperties);
returnframeDuration;
}
总结一下:一般涉及到第三方自定义,还是应该多多熟悉官方api,这个小功能我在网上瞎找,就浪费了半天;