"淡入淡出"动画不起作用

时间:2016-08-06 02:09:21

标签: swift xcode

我有一段代码,我在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: {
            })
        }
        
    }




1 个答案:

答案 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()
    }
}