Reputation: 11
I have a piece of code that I wrote in the view controller of Xcode. Before that code, even the button called NEXTTIP works. But now, after adding in the animation, the animation does not come out and the button does not work. Please Help!
@IBAction func nextTip(sender: AnyObject) {
func hideTip() {
UIView.animateWithDuration(0.5,
animations: {
self.titleLabel.alpha = 0
self.contentLabel.alpha = 0
self.imageView.alpha = 0
},
completion: { finished in
self.showTip
}
)
}
func showTip() {
titleLabel.text = "For healthy teeth, don't brush after eating"
contentLabel.text = "Don't brush your teeth immediately after meals and drinks, especially if they were acidic. Wait 30 to 60 minutes before brushing."
imageView.image = UIImage(named:"teeth.jpg")
UIView.animateWithDuration(0.5,
animations: {
})
}
}
Upvotes: 1
Views: 93
Reputation: 17724
What you're doing inside the nextTip()
function is defining two new functions, hideTip()
and showTip()
. You're not actually calling them. Creating functions inside functions in Swift is a perfectly legal thing to do, but is almost certainly not what you want to do here. You need to move the definitions for hideTip()
and showTip()
outside of the nextTip(:)
function, so your code would be structured like so:
class MyViewController: UIViewController {
func hideTip() {
UIView.animateWithDuration(...)
// etc.
}
func showTip() {
// stuff
}
@IBAction func nextTip(sender: AnyObject) {
hideTip()
}
}
Upvotes: 2