我在Xcode的标签应用中遇到了动画问题。
我有viewDidLoad
和viewDidAppear
部分,问题是我有两个标签label1
和label2
。我希望label1
只在应用程序加载时出现一次,并且每次我返回到FirstView时都会出现label2
。
所以合乎逻辑的做法是:
override func viewDidLoad(animated: Bool) {
super.viewDidLoad()
self.label1.alpha = 0
self.label2.alpha = 0
//this is the animation
UIView.animateWithDuration(2.0, animations: { () -> Void in
self.label1.alpha = 1.0
//this is what happens after a delay
[DELAY CODE]
self.label1.alpha = 0.0
})
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(2.0, animations: { () -> Void in
self.label2.alpha = 1.0
}
基本上应该做的是让label1
出现并且只消失一次,并且每次label2
出现在屏幕上时都会显示firstView
。问题是我在第一行有一个错误告诉我“方法不会覆盖其超类中的任何方法”。那么我怎样才能做到我想要实现的目标呢?
答案 0 :(得分:2)
答案 1 :(得分:0)
试试这个:
UIView.animateWithDuration(2.0,
animations: { () -> Void in
// Your animation method
self.label1.alpha = 1.0
}) { (Bool) -> Void in
// Call your delay method here.
// Delay - 3 seconds
NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(3),
target: self,
selector: "hideLabel",
userInfo: nil,
repeats: false)
}
//
func hideLabel {
UIView.animateWithDuration(2,
animations: { () -> Void in
self.label1.alpha = 0.0
})
}