我有一段代码,我在Xcode的视图控制器中编写。在该代码之前,甚至名为NEXTTIP的按钮也可以工作。但现在,在添加动画后,动画没有出现,按钮不起作用。请帮助!
@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: {
})
}
}

答案 0 :(得分:2)
您在nextTip()
函数中执行的操作是定义两个新函数hideTip()
和showTip()
。你实际上并没有打电话给他们。在Swift中创建函数内部的函数是完全合法的事情,但几乎肯定不是你想在这里做的。您需要在hideTip()
函数之外移动showTip()
和nextTip(:)
的定义,因此您的代码结构如下:
class MyViewController: UIViewController {
func hideTip() {
UIView.animateWithDuration(...)
// etc.
}
func showTip() {
// stuff
}
@IBAction func nextTip(sender: AnyObject) {
hideTip()
}
}