ios - map 上的自定义图钉(注释)动画

标签 ios objective-c swift animation mapkit

我想要 map 上的自定义图钉注释。我有动画代码,但我似乎无法将其实现为 map 上的注释。

我的圆圈动画代码是:

func animation() {
    // The circle in its smallest size.
    let circlePath1 = UIBezierPath(arcCenter: CGPoint(x: 200,y: 150), radius: CGFloat(3), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

    // The circle in its largest size.
    let circlePath2 = UIBezierPath(arcCenter: CGPoint(x: 200,y: 150), radius: CGFloat(60), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

    // Configure the layer.
    let shapeLayer = CAShapeLayer()
    shapeLayer.strokeColor = green.CGColor
    shapeLayer.fillColor = green.CGColor
    // This is the path that's visible when there'd be no animation.
    shapeLayer.path = circlePath1.CGPath
    self.layer.addSublayer(shapeLayer)

    // Animate the path.
    let pathAnimation = CABasicAnimation(keyPath: "path")
    pathAnimation.fromValue = circlePath1.CGPath
    pathAnimation.toValue = circlePath2.CGPath

    // Animate the alpha value.
    let alphaAnimation = CABasicAnimation(keyPath: "opacity")
    alphaAnimation.fromValue = 1
    alphaAnimation.toValue = 0

    // We want both animations to run together perfectly, so we
    // put them into an animation group.
    let group = CAAnimationGroup()
    group.animations = [pathAnimation, alphaAnimation]
    group.duration = 2.4
    group.repeatCount = FLT_MAX

    // Add the animation to the layer.
    shapeLayer.addAnimation(group, forKey:"sonar")

}

这是 map 的一些代码:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    let identifier = "MyPin"

    if annotation.isKindOfClass(MKUserLocation) {
        return nil
    }

    // Reuse the annotation if possible
    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)

    if annotationView == nil {

        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "pin")

        // I have an image here, but instead I want my custom animation
        annotationView!.image = UIImage(named: "watch")

    } else {
        annotationView!.annotation = annotation
    }

    return annotationView
}

我目前有一个名为 watch 的自定义图像用于 pin 注释,但我想要的是这个动画。有什么想法吗?

最佳答案

这里有一些灵感:

https://github.com/TransitApp/SVPulsingAnnotationView

相似但不同。但我认为很多技术都是相同的。

关于ios - map 上的自定义图钉(注释)动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36439922/

相关文章:

objective-c - Command-Click 从 Objective-C 源到 Swift 打开 MyProject-Swift.h 文件

ios - 快速引用子类中的 Outlet

ios - UIActivityIndi​​cator 不工作

ios - 分享 iOS development.provision 文件

ios - 嵌入式 Youtube 播放列表未在 IOS 设备上显示

objective-c - 如何在不子类化 NSString 的情况下在特定的 [nsstring release] 处设置断点?

ios - 每部分一个复选标记

objective-c - iOS 模糊文本 : detecting & solving it once and for all?

iphone - 何时删除 iOS 钥匙串(keychain)项目?

ios - 升级到 swift 3.0 后,检查街景可用性不起作用。谷歌地图sdk