【问题标题】:Replicate radiating circles like user location on MKMapView在 MKMapView 上复制像用户位置这样的辐射圈
【发布时间】:2011-12-11 06:36:02
【问题描述】:

是否可以像用户位置注释一样具有辐射圈。以便自定义注释具有其他颜色的辐射圈。如果没有,有没有办法让它工作?

【问题讨论】:

    标签: objective-c ios mkmapview core-location


    【解决方案1】:

    看看这个。你可以用它做你需要的。结合使用核心动画和子类化MKCircleViewMKOverlayView

    http://yickhong-ios.blogspot.com/2012/04/animated-circle-on-mkmapview.html

    【讨论】:

    • 这绝对是我想要的,我对其进行了一些编辑,而不是使用图像,而是使用图形上下文创建图像。非常感谢,太棒了
    【解决方案2】:

    可以创建 UIView 的自定义子类来执行此操作。一个带有两个子层的 UIView,一个用于中心球,一个用于扩展环。环层和球层可以通过继承 CALayer 并覆盖 drawInContext: 来创建,这样你就可以得到任何你想要的颜色。为环设置动画以便它们同时展开和淡出的代码可以使用这样的 CAAnimationGroup:

    // expand the ring from the ball size to the ring's max size
    CABasicAnimation *sizeAnim = [CABasicAnimation animationWithKeyPath:@"bounds"];
    sizeAnim.fromValue   = [NSValue valueWithCGRect:ballBounds];
    sizeAnim.toValue     = [NSValue valueWithCGRect:ringBoundsMax];
    sizeAnim.duration    = kRingExpansionTime;
    
    // fade out the ring part way thru the animation
    CABasicAnimation* alphaAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    alphaAnim.fromValue   = [NSNumber numberWithFloat:1];
    alphaAnim.toValue     = [NSNumber numberWithFloat:0];
    alphaAnim.beginTime   = kRingExpansionTime * 0.7f;      // start part way thru
    alphaAnim.duration    = kRingExpansionTime - alphaAnim.beginTime;
    
    CAAnimationGroup* group = [CAAnimationGroup animation];
    group.duration    = kRingExpansionTime;
    group.repeatCount = HUGE_VALF;      // repeat forever
    group.animations  = [NSArray arrayWithObjects:sizeAnim, alphaAnim, nil];
    [ringLayer addAnimation:group forKey:nil];
    

    【讨论】:

    • 感谢您的回答。你知道是否可以将它放在 MKAnnotation/MKOverlay 中,以便在放大/缩小时可以缩放?
    猜你喜欢
    • 1970-01-01
    • 2011-09-18
    • 2011-08-29
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-04
    相关资源
    最近更新 更多