我正在处理我的应用程序的一部分,在该应用程序中,我根据用户的时间进度为消息制作动画。因此,基本上是超时消息。
我有一个柜台和两个标签:
var timer = NSTimer()
var timerCount = 0
@IBOutlet weak var bannerLabel: UILabel!
@IBOutlet weak var messageLabel: UILabel!
我有一个调用计数方法(countingUp)的 NSTimer,其中我的timerCount
变量递增。当然,正如人们所期望的那样,该方法每秒都会触发一次。该countingUp
方法调用一个名为updateLabels
(每秒)的方法。
func countingUp() {
// other irrelevant stuff
updateLabels()
timerCount++
}
func updateLabels() {
if timerCount == 1 {
animateMessage(messageLabel, delay: 7.0)
animateBanner(bannerLabel, delay: 7.0)
bannerLabel.text = "Message 1"
messageLabel.text = "Blah Blah"
}
// quite a few more of these conditions, though
// I use a switch in my app.
}
这是我的动画方法:
func animateBanner(banner: UILabel, delay: Double){
UIView.animateWithDuration(1.2, animations: {
banner.alpha = 1.0
})
if delay > 0.0 {
UIView.animateWithDuration(3, delay: delay, options: [], animations: {
banner.alpha = 0.1
}, completion: nil)
}
}
func animateMessage(label: UILabel, delay: Double){
label.alpha = 0.0
UIView.animateWithDuration(1.2, animations: {
label.center.y -= 20
label.alpha = 1.0
})
UIView.animateWithDuration(1.2, delay: delay, options: [], animations: {
label.alpha = 0.1
}, completion: nil)
}
为了证明我的方法正在被调用并且我的标签确实处于 alpha 的状态,0
我截取了一个屏幕截图:
我的问题:
我的动画完美地淡出,但它们从不淡入,它们只是出现。这是什么原因?