复制辐射圆,例如 MKMapView 上的用户位置

发布于 2024-12-10 17:36:58 字数 69 浏览 0 评论 0原文

是否可以有像用户位置注释那样的放射状圆圈。这样自定义注释就有其他颜色的放射状圆圈。如果没有,是否有一种破解方法可以使其工作?

Is it possible to have the radiating circles like the user location annotation. So that custom annotations have radiating circles of other colors. If not is there a hack way to make it work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美人迟暮 2024-12-17 17:36:58

看看这个。您也许可以用它来做您需要做的事情。结合使用核心动画和子类化 MKCircleViewMKOverlayView

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

Check this out. You may able to do what you need with that. With a combination of using Core Animation and subclassing MKCircleView or MKOverlayView.

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

爱已欠费 2024-12-17 17:36:58

可以创建 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];

It is possible to create a custom subclass of UIView that does this. A UIView with two sublayers, one for the center ball and one for the expanding rings. The ring layer and the ball layer can be created by subclassing CALayer and overriding drawInContext: so you can get any colors you want. Code to animate the rings so that they expand and fade out at the same time could use a CAAnimationGroup like this:

// 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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文