2017-05-23 6 views
2

GMSMarkerをアニメーション化して、カップル秒で1回パルスするようにしています。サークルスケールのアニメーションがちょっと変わっています

func addWave() 
    { 
//  circleView.layer.cornerRadius = size/2 

     //Scale 
     let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") 
     scaleAnimation.fromValue = 1 
     scaleAnimation.toValue = zoom 

     //Opacity 
     let alphaAnimation = CABasicAnimation(keyPath: "opacity") 
     alphaAnimation.toValue = 0.0 

     //Corner radius 
//  let cornerRadiusAnimation = CABasicAnimation(keyPath: "cornerRadius") 
//  cornerRadiusAnimation.fromValue = size/2 
//  cornerRadiusAnimation.toValue = (size * zoom)/2 

     //Animation Group 
     let animations: [CAAnimation] = [scaleAnimation, alphaAnimation] 

     let animationGroup = CAAnimationGroup() 
     animationGroup.duration = duration 
     animationGroup.animations = animations 
     animationGroup.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 
     animationGroup.repeatCount = 1 
     animationGroup.fillMode = kCAFillModeForwards 
     animationGroup.isRemovedOnCompletion = false 
     circleView.layer.add(animationGroup, forKey: "group") 
    } 

結果は次のようになります。

enter image description hereenter image description here

そして、私はCorner radiusセクションのコメントを外した場合には、次のようになります。

enter image description here

だから私はアドバイスを必要としています。

答えて

5

私の所見によると、私はそれがあなたのCAShapeLayerの間違った経路の問題でなければならないと思うので、サークルのマスキングです。

私はちょうどレーダーのアニメーションを書いた、私はあなたを助けてくれることを願っています。私が何をしたか

let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") 
    scaleAnimation.fromValue = 0 
    scaleAnimation.toValue = 1 

    let alphaAnimation = CABasicAnimation(keyPath: "opacity") 
    alphaAnimation.fromValue = 1 
    alphaAnimation.toValue = 0 

    let animations = CAAnimationGroup() 
    animations.duration = 0.8 
    animations.repeatCount = Float.infinity 
    animations.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 
    animations.animations = [scaleAnimation, alphaAnimation] 

    circleView.layer.add(animations, forKey: "animations") 

た、私は2つのCAShapeLayer(オレンジマーカー及びその他のもの1はマーカーの後ろにレーダー層である)を使用。アニメーションはレーダーレイヤーに適用されました。

radarLayer = CAShapeLayer() 
    radarLayer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: self.frame.size.height); 
    radarLayer.path = UIBezierPath(rect: radarLayer.frame).cgPath 
    radarLayer.fillColor = UIColor.orange.cgColor 
    radarLayer.position = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2) 
    radarLayer.cornerRadius = radarLayer.frame.size.width/2 
    radarLayer.masksToBounds = true 
    radarLayer.opacity = 0 
    self.layer.addSublayer(radarLayer) 

    circleLayer = CAShapeLayer() 
    circleLayer.frame = CGRect(x: 0, y: 0, width: 16, height: 16); 
    circleLayer.path = UIBezierPath(rect: circleLayer.frame).cgPath 
    circleLayer.fillColor = UIColor.orange.cgColor 
    circleLayer.position = CGPoint(x: self.frame.size.width/2, y: self.frame.size.height/2) 
    circleLayer.cornerRadius = circleLayer.frame.size.width/2 
    circleLayer.masksToBounds = true 
    self.layer.addSublayer(circleLayer) 

PS。私は、スウィフトに新たなんだので、私はどこか間違っているなら、私を啓発:)

例:http://i.imgur.com/v2jFWgw.jpg

+0

ありがとうございました!私は層と基本的な知識を台無しにしたように見える、あなたの答えは私がそれを得るのを助けた:) – Edward

関連する問題