gpt4 book ai didi

swift - "Fade in and out"动画不工作

转载 作者:搜寻专家 更新时间:2023-11-01 07:21:23 29 4
gpt4 key购买 nike

我有一段代码是我在 Xcode 的 View Controller 中编写的。在该代码之前,即使是名为 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: {
})
}

}

最佳答案

您在 nextTip() 函数中所做的是定义两个新函数,hideTip()showTip( )。你实际上并没有给他们打电话。在 Swift 的函数内部创建函数是一件完全合法的事情,但几乎可以肯定这不是你想在这里做的。您需要将 hideTip()showTip() 的定义移到 nextTip(:) 函数之外,以便您的代码结构化像这样:

class MyViewController: UIViewController {
func hideTip() {
UIView.animateWithDuration(...)
// etc.
}

func showTip() {
// stuff
}

@IBAction func nextTip(sender: AnyObject) {
hideTip()
}
}

关于swift - "Fade in and out"动画不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38799953/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com