Reputation: 246
I'm having some trouble with the animations in a tabbed app in Xcode.
I have the viewDidLoad
and the viewDidAppear
parts, the problem is that I have two labels label1
and label2
. I would like label1
appearing only once when the application loads, and label2
appearing every time I go back to the FirstView.
So the logical thing to do would be:
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
}
Essentially what this should do is make label1
appear and disappear only once, and make label2
appear every time firstView
shows up on the screen. The problem is that I have an error in the first line telling me "Method does not override any method from its superclass". So how can I do what I am trying to achieve?
Upvotes: 0
Views: 1079
Reputation: 596
Try This :
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
})
}
Upvotes: 0
Reputation: 22343
You have to remove the animated:Bool
from your viewDidLoad
-method. there is no such parameter in this method.
So it should look like that:
override func viewDidLoad() {
Upvotes: 2