如何在GMSMapView上设置自定义标注标记(点附近的animation环)
使用谷歌地图iOS SDK我已经实现了一个mapView,我已经创build了如下标记
// Creates a marker in the center of the map. GMSMarker *marker = [[GMSMarker alloc] init]; marker.position = CLLocationCoordinate2DMake(-33.86, 151.20); marker.title = @"Sydney"; marker.snippet = @"Australia"; marker.icon = [UIImage imageNamed:@"point1.png"]; marker.map = mapView_;
但我需要显示animation图像,即一些图像序列显示,围绕一个点的animation环,而不是原来的GMSMarker
图像序列是point1.png point2.png point3.png point4.png point5.png
任何人都可以帮助我做到这一点
在
- (RMMapLayer *)mapView:(RMMapView *)mpView layerForAnnotation:(RMAnnotation *)annotation { UIImageView *pulseRingImg = [[UIImageView alloc] initWithFrame: CGRectMake(-30, -30, 78, 78)]; pulseRingImg.image = [UIImage imageNamed:@"PulseRing.png"]; pulseRingImg.userInteractionEnabled = NO; CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.xy"]; theAnimation.duration=2.0; theAnimation.repeatCount=HUGE_VALF; theAnimation.autoreverses=NO; pulseRingImg.alpha=0; theAnimation.fromValue=[NSNumber numberWithFloat:0.0]; theAnimation.toValue=[NSNumber numberWithFloat:1.0]; pulseRingImg.alpha = 1; [pulseRingImg.layer addAnimation:theAnimation forKey:@"pulse"]; pulseRingImg.userInteractionEnabled = NO; [mapView addSubview:pulseRingImg]; [marker addSublayer:pulseRingImg.layer]; return marker; }
[UIImage imageNamed:@"PulseRing.png"]
中的[UIImage imageNamed:@"PulseRing.png"]
是
从以下获取参考:
ios – 如何在UIButton上实现本机“脉冲效果”animation
CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; theAnimation.duration=1.0; theAnimation.repeatCount=HUGE_VALF; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; theAnimation.toValue=[NSNumber numberWithFloat:0.0]; [myButton.layer addAnimation:theAnimation forKey:@"animateOpacity"];
从谷歌地图sdk /它出现在这个时候v1.9是唯一支持使用基于帧的图像animation。 如果你使用mapkit – >你可以简单地使用https://github.com/TransitApp/SVPulsingAnnotationView
从谷歌的sdk – > ios示例
AnimatedCurrentLocationViewController.m
NSMutableArray *frames = [NSMutableArray array]; for (int i =0; i<146; i++) { NSString *img = [NSString stringWithFormat:@"pulse-%d",i]; [frames addObject:[UIImage imageNamed:img]]; } marker.icon = [UIImage animatedImageWithImages:frames duration:3];
在我的animation书的分支https://github.com/johndpope/Flipbook我已经渲染了视网膜脉冲animation到一堆透明PNG图像。 有可能在Photoshop中进一步减less这些文件的大小。 当然这并不理想,会导致你的二进制文件大小膨胀,但是可以通过。
你尝试过吗? https://github.com/shu223/Pulsator
启动并添加到您的视图的图层,然后调用开始!
let pulsator = Pulsator() view.layer.addSublayer(pulsator) pulsator.start()
对于SWIFT 3:
您可以使用UIImage.animatedImage作为标记的图标,如下所示:
-
用不同的图像创build一个UIImage数组
let image1 = UIImage(named: "marker-image-1") let image2 = UIImage(named: "marker-image-2") let image3 = UIImage(named: "marker-image-3") let imagesArray = [image1,image2,image3]
-
设置您的标记的图标:
marker.icon = UIImage.animatedImage(with: imagesArray as! [UIImage], duration: 1.2) marker.map = mapView
-
您可以更改animation的持续时间
-
运行你的应用程序,你会看到用不同的图像animation的标记
您可以通过更改标记图标属性来自定义标记。
例如:london.icon = [UIImage imageNamed:@“house”]; 你可以在那里给自己的图像或一些编辑的图像。
如果您要自定义在点击标记后将显示的infowindow。
请参阅该链接