Ios 地图上的自定义pin(注释)动画
我想在地图上自定义pin注释。我有动画代码,但似乎无法将其作为地图上的注释来实现 我的圆动画代码是:Ios 地图上的自定义pin(注释)动画,ios,objective-c,swift,animation,mapkit,Ios,Objective C,Swift,Animation,Mapkit,我想在地图上自定义pin注释。我有动画代码,但似乎无法将其作为地图上的注释来实现 我的圆动画代码是: 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)
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
,用于pin注释,但我想要的是这个动画。有什么想法吗?这里有一些灵感:
相似但不同。但我认为很多技巧都是一样的。这里有一些灵感:
相似但不同。但我认为很多技术都是一样的。嘿,这非常有用,它确实让我走得更远。唯一的问题是,当我在地图上滚动或离开应用程序返回时,我的动画会冻结(停止)。我对上面链接中的代码理解不够,无法尝试将他的一些想法应用到我的应用程序中,因为我还行,但不太擅长Objective-C。有没有关于如何解决这个问题的想法?嘿,这非常有用,它确实让我走得更远。唯一的问题是,当我在地图上滚动或离开应用程序返回时,我的动画会冻结(停止)。我对上面链接中的代码理解不够,无法尝试将他的一些想法应用到我的应用程序中,因为我还行,但对Objective-C不太在行。有什么想法可以解决这个问题吗?