【发布时间】:2011-12-11 06:36:02
【问题描述】:
是否可以像用户位置注释一样具有辐射圈。以便自定义注释具有其他颜色的辐射圈。如果没有,有没有办法让它工作?
【问题讨论】:
标签: objective-c ios mkmapview core-location
是否可以像用户位置注释一样具有辐射圈。以便自定义注释具有其他颜色的辐射圈。如果没有,有没有办法让它工作?
【问题讨论】:
标签: objective-c ios mkmapview core-location
看看这个。你可以用它做你需要的。结合使用核心动画和子类化MKCircleView 或MKOverlayView。
http://yickhong-ios.blogspot.com/2012/04/animated-circle-on-mkmapview.html
【讨论】:
可以创建 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];
【讨论】: