產(chǎn)品需要等待界面有一個(gè)雷達(dá)效果,之前做過百度的,新接手需要做高德的,網(wǎng)上找了半天還是自己實(shí)現(xiàn)了,其實(shí)很簡單,直接自定義高德地圖定位小藍(lán)點(diǎn),用GIF替換就有效果.上代碼
MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];
//? ? r.strokeColor = [UIColor blueColor];
//? ? r.fillColor = [UIColor redColor];
//? ? r.lineWidth = 4;
//? ? r.enablePulseAnnimation = YES;
? ? ? r.showsAccuracyRing = NO;///精度圈是否顯示,默認(rèn)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];
上面這兩個(gè)方法是將從UI拿拿到的GIF轉(zhuǎn)給image.這樣實(shí)現(xiàn)更便捷,更簡單,樣式可選性也比較強(qiáng).
- (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;
}
總結(jié)一下:一般涉及到第三方自定義,還是應(yīng)該多多熟悉官方api,這個(gè)小功能我在網(wǎng)上瞎找,就浪費(fèi)了半天;