我想在地图上使用自定义图钉注释。我有动画代码,但我似乎无法将其作为地图上的注释来实现。
我的圆圈动画代码是:
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")
}
以下是地图的一些代码:
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
的自定义图像用于图钉注释,但我想要的是这个动画。有什么想法吗?
答案 0 :(得分:0)