【发布时间】:2015-09-16 16:35:39
【问题描述】:
我正在开发我的应用程序的一部分,在该应用程序中,我根据用户的时间进度为消息制作动画。所以,基本上是超时消息。
我有一个计数器和两个标签:
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)
}
为了证明我的方法正在被调用并且我的标签确实是0的alpha,我截取了一个屏幕截图:
我的问题:
我的动画完美地淡出,但它们从不淡入,它们只是出现。这是什么原因?
【问题讨论】:
标签: swift uiviewanimation swift2 animatewithduration xcode7-beta2