ios – 如何在GMSMapView上设置自定义注释标记(围绕点的动画环)

前端之家收集整理的这篇文章主要介绍了ios – 如何在GMSMapView上设置自定义注释标记(围绕点的动画环)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用谷歌地图iOS SDK我已经实现了mapView
因为我已经创建了如下标记
  1. // Creates a marker in the center of the map.
  2. GMSMarker *marker = [[GMSMarker alloc] init];
  3. marker.position = CLLocationCoordinate2DMake(-33.86,151.20);
  4. marker.title = @"Sydney";
  5. marker.snippet = @"Australia";
  6.  
  7. marker.icon = [UIImage imageNamed:@"point1.png"];
  8.  
  9. marker.map = mapView_;

但我需要显示动画图像,即要显示的一些图像序列,一个点周围的动画环,而不是原始的GMSMarker

图像序列为point1.png point2.png point3.png point4.png point5.png

任何人都可以帮助我实现这一目标

解决方法

  1. - (RMMapLayer *)mapView:(RMMapView *)mpView layerForAnnotation:(RMAnnotation *)annotation
  2. {
  3.  
  4. UIImageView *pulseRingImg = [[UIImageView alloc] initWithFrame: CGRectMake(-30,-30,78,78)];
  5. pulseRingImg.image = [UIImage imageNamed:@"PulseRing.png"];
  6. pulseRingImg.userInteractionEnabled = NO;
  7.  
  8. CABasicAnimation *theAnimation;
  9. theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];
  10. theAnimation.duration=2.0;
  11. theAnimation.repeatCount=HUGE_VALF;
  12. theAnimation.autoreverses=NO;
  13. pulseRingImg.alpha=0;
  14. theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
  15. theAnimation.toValue=[NSNumber numberWithFloat:1.0];
  16. pulseRingImg.alpha = 1;
  17. [pulseRingImg.layer addAnimation:theAnimation forKey:@"pulse"];
  18. pulseRingImg.userInteractionEnabled = NO;
  19.  
  20. [mapView addSubview:pulseRingImg];
  21. [marker addSublayer:pulseRingImg.layer];
  22.  
  23. return marker;
  24.  
  25. }

[UIImage imageNamed:@“PulseRing.png”]中的PulseRing.png是

参考来自:

ios – how to do a native “Pulse effect” animation on a UIButton

  1. CABasicAnimation *theAnimation;
  2.  
  3. theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
  4. theAnimation.duration=1.0;
  5. theAnimation.repeatCount=HUGE_VALF;
  6. theAnimation.autoreverses=YES;
  7. theAnimation.fromValue=[NSNumber numberWithFloat:1.0];
  8. theAnimation.toValue=[NSNumber numberWithFloat:0.0];
  9. [myButton.layer addAnimation:theAnimation forKey:@"animateOpacity"];

猜你在找的iOS相关文章