私はAndroidの材料設計の円形不定活動の指標に似たカスタムアクティビティインジケータを作成しようとしています。基本的には、円を2回描いて消去したいのですが、消去と描画が同時にやって来るわけではありません。これは今まで私が持っているものです:接続2つのstrokeEndアニメーション
let progressLayer = CAShapeLayer()
progressLayer.strokeColor = UIColor.red().cgColor
progressLayer.fillColor = nil
progressLayer.lineWidth = 2
let drawAnimation = CABasicAnimation(keyPath: "strokeEnd")
drawAnimation.duration = duration/2
drawAnimation.fromValue = 0
drawAnimation.toValue = 1
drawAnimation.isRemovedOnCompletion = false
drawAnimation.fillMode = kCAFillModeForwards
let eraseAnimation = CABasicAnimation(keyPath: "strokeStart")
eraseAnimation.duration = duration/2
eraseAnimation.beginTime = 0.2
eraseAnimation.fromValue = 0
eraseAnimation.toValue = 0.4
eraseAnimation.isRemovedOnCompletion = false
eraseAnimation.fillMode = kCAFillModeForwards
let endDrawAnimation = CABasicAnimation(keyPath: "strokeEnd")
endDrawAnimation.beginTime = duration/2
endDrawAnimation.duration = duration/2
endDrawAnimation.fromValue = 0
endDrawAnimation.toValue = 1
endDrawAnimation.isRemovedOnCompletion = false
endDrawAnimation.fillMode = kCAFillModeForwards
let endEraseAnimation = CABasicAnimation(keyPath: "strokeStart")
endEraseAnimation.beginTime = duration/2
endEraseAnimation.duration = duration/4
endEraseAnimation.fromValue = 0.4
endEraseAnimation.toValue = 1
endEraseAnimation.isRemovedOnCompletion = false
endEraseAnimation.fillMode = kCAFillModeForwards
let endEraseAnimation2 = CABasicAnimation(keyPath: "strokeStart")
endEraseAnimation2.beginTime = duration * 3/4
endEraseAnimation2.duration = duration/4
endEraseAnimation2.fromValue = 0
endEraseAnimation2.toValue = 1
endEraseAnimation2.isRemovedOnCompletion = false
endEraseAnimation2.fillMode = kCAFillModeForwards
let animations = CAAnimationGroup()
animations.duration = duration
animations.animations = [drawAnimation, eraseAnimation, endDrawAnimation, endEraseAnimation, endEraseAnimation2]
animations.isRemovedOnCompletion = false
animations.fillMode = kCAFillModeForwards
progressLayer.add(animations, forKey: "stroke")
コードは、1つの問題を除いて、すべて期待通りに動作します。最初のstrokeEnd
アニメーションが終了し、2番目のアニメーションが開始されると、その点が描かれていた円の部分が消えて、0から再び描画が開始されることを意味するフラッシュがあります。これを修正する方法はありますか?
あなたのコードショーのエラー私がコンパイルしようとすると、助けるために、あなたの実際のコードを入れてくださいあなた –
@ReinierMelianこれはSwift 3コードです.Xcode 8を使用しているか、Swift 2に翻訳していることを確認してください。@Banana、 'progressLayer'は何ですか? – JAL
'progressLayer'は' CAShapeLayer'です。これを上記の質問に追加しました。 – Banana