イメージをフェードアウトするanimateWithDurationコードを呼び出すボタンがあり、テキスト&が新しいbgのカラーをフェードして元に戻します。アニメーションは数秒で完成し、素晴らしい作品です。連続したアニメーションの呼び出しが機能しない
ただし、問題があります:
アニメーションが終了する前にこのボタンが再度押されることがあります。これが起こると、私は現在のアニメーションを止めて、やり直して欲しい。
私の読書によると
を動作しない解決策を研究し、解決策は単純である必要があり、ちょうどQuartzCoreをインポートして追加します。
button.layer.removeAllAnimations()
このアニメーションを削除しますが、新しい/秒のアニメーションがあるん完全に混乱した。隠されているはずの画像はありません。テキストは表示されず、色の変化はすべて間違っています。何が起こっていますか!?!
//Animate Finished feedback in footer bar
func animateFinished(textToDisplay: String, footerBtn: UIButton, footerImg: UIImageView) {
//Should cancel any current animation
footerBtn.layer.removeAllAnimations()
footerBtn.alpha = 0
footerBtn.setTitle(textToDisplay, forState: UIControlState.Normal)
footerBtn.titleLabel!.font = UIFont(name: "HelveticaNeue-Regular", size: 18)
footerBtn.setTitleColor(UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0), forState: UIControlState.Normal)
footerBtn.backgroundColor = UIColor(red: 217/255.0, green: 217/255.0, blue: 217/255.0, alpha: 1.0)
UIView.animateWithDuration(0.5, delay: 0.0, options: nil, animations: {
footerImg.alpha = 0.01 //Img fades out
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 163/255.0, blue: 00/255.0, alpha: 0.6)
}
, completion: { finished in
UIView.animateWithDuration(0.5, delay: 0.0, options: nil, animations: {
footerBtn.alpha = 1 //Text fades in
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 208/255.0, blue: 11/255.0, alpha: 0.6)
}
, completion: { finished in
UIView.animateWithDuration(0.5, delay: 1.0, options: nil, animations: {
footerBtn.alpha = 0.01 //Text fades out
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 173/255.0, blue: 00/255.0, alpha: 0.6)
}
, completion: { finished in
UIView.animateWithDuration(0.5, delay: 0.0, options: nil, animations: {
footerImg.alpha = 1 //Img fades in
}
, completion: { finished in
footerBtn.backgroundColor = UIColor.clearColor()
footerBtn.setTitleColor(UIColor(red: 55/255.0, green: 55/255.0, blue: 55/255.0, alpha: 1.0), forState: UIControlState.Normal)
footerBtn.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 18)
footerBtn.setTitle("", forState: UIControlState.Normal)
footerBtn.alpha = 1
//Completion blocks sets values back to norm
})
})
})
})
}//End of animation
@Shripada @Shripadaは、わかりやすいコードをキーフレームに切り替えることをお勧めします。以下のキーフレーム形式。アニメーションの中断の問題は解決しませんでした。ネストまたはキーフレーム形式で問題を解決できる場合は、投稿してください!
func animateFinished(textToDisplay: String, footerBtn: UIButton, footerImg: UIImageView) {
//Should cancel any current animation
footerBtn.layer.removeAllAnimations()
footerBtn.alpha = 0
footerBtn.setTitle(textToDisplay, forState: UIControlState.Normal)
footerBtn.titleLabel!.font = UIFont(name: "HelveticaNeue-Regular", size: 18)
footerBtn.setTitleColor(UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0), forState: UIControlState.Normal)
//footerBtn.backgroundColor = UIColor(red: 217/255.0, green: 217/255.0, blue: 217/255.0, alpha: 1.0)
UIView.animateKeyframesWithDuration(3.0 /*Total*/, delay:0.0, options: UIViewKeyframeAnimationOptions.CalculationModeLinear, animations: {
UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration:0.10, animations:{
footerImg.alpha = 0.01 //Img fades out
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 103/255.0, blue: 00/255.0, alpha: 0.6) //Bg turns to green
})
UIView.addKeyframeWithRelativeStartTime(0.10, relativeDuration:0.30, animations:{
footerBtn.alpha = 1 //Text and green bg fades in
footerBtn.backgroundColor = UIColor(red: 46/255.0, green: 173/255.0, blue: 11/255.0, alpha: 0.6) //BG turns greener
})
UIView.addKeyframeWithRelativeStartTime(0.40, relativeDuration:0.50, animations:{
footerBtn.alpha = 0.01 //Text fades out & bg fade out
})
},
completion: { finished in
footerImg.alpha = 1
footerBtn.alpha = 1
footerBtn.backgroundColor = UIColor.clearColor()
footerBtn.setTitleColor(UIColor(red: 55/255.0, green: 55/255.0, blue: 55/255.0, alpha: 1.0), forState: UIControlState.Normal)
footerBtn.titleLabel!.font = UIFont(name: "HelveticaNeue-Light", size: 18)
footerBtn.setTitle("", forState: UIControlState.Normal)
//Completion blocks sets values back to norm
}
)
}//End of 'Finished' animation
...そうではありません...あなたは私のヒーローです。それは魅力のように働いた。私はこれらの3本の線を貼り付けました。それは魔法と似ていました。あなたは魔術師のヒーローです。ありがとうございました! –