使用场景
在地图中的定位图标展示时,呈现出定位圈向外扩散的动画效果。让定位展示效果更加明显、酷炫。
用到产品
核心类/接口
类接口说明版本
RadialCircleAnnotationView----继承自MAAnnotationView,实现脉冲圈向外缩放的动画效果----
MAMapView- (void)addAnnotation:(id )annotation;向地图窗口添加标注V4.0.0起
核心难点
增加RadialCircleAnnotationView
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation
{
if ([annotation isKindOfClass:[MAPointAnnotation class]])
{
static NSString *pointReuseIdentifier = @"pointReuseIdentifier";
RadialCircleAnnotationView *annotationView = (RadialCircleAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pointReuseIdentifier];
if (annotationView == nil)
{
annotationView = [[RadialCircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pointReuseIdentifier];
annotationView.canShowCallout = YES;
//脉冲圈个数
annotationView.pulseCount = 4;
//单个脉冲圈动画时长
annotationView.animationDuration = 8.0;
//单个脉冲圈起始直径
annotationView.baseDiameter = 8.0;
//单个脉冲圈缩放比例
annotationView.scale = 30.0;
//单个脉冲圈fillColor
annotationView.fillColor = [UIColor colorWithRed:24.f/255.f green:137.f/255.f blue:234.f/255.f alpha:1.0];
//单个脉冲圈strokeColor
annotationView.strokeColor = [UIColor colorWithRed:35.f/255.f green:35.f/255.f blue:255.f/255.f alpha:1.0];
}
return annotationView;
}
return nil;
}
/* 增加RadialCircleAnnotationView. */
func mapView(_ mapView: MAMapView!, viewFor annotation: MAAnnotation!) -> MAAnnotationView! {
if annotation is MAPointAnnotation {
let pointReuseIndetifier = "pointReuseIdentifier"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier) as? RadialCircleAnnotationView
if annotationView == nil {
annotationView = RadialCircleAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
}
annotationView?.canShowCallout = true
//脉冲圈个数
annotationView?.pulseCount = 4
//单个脉冲圈动画时长
annotationView?.animationDuration = 8.0
//单个脉冲圈起始直径
annotationView?.baseDiameter = 8.0
//单个脉冲圈缩放比例
annotationView?.scale = 30.0
//单个脉冲圈fillColor
annotationView?.fillColor = UIColor(red: 24.0/255.0, green: 137.0/255.0, blue: 234.0/255.0, alpha: 1.0)
//单个脉冲圈strokeColor
annotationView?.strokeColor = UIColor(red: 35.0/255.0, green: 35.0/255.0, blue: 255.0/255.0, alpha: 1.0)
//更改设置后重新开始动画
annotationView?.startPulseAnimation()
return annotationView
}
return nil
}