【发布时间】:2020-05-30 17:23:37
【问题描述】:
当我尝试在viewDidLoad() 中调用动画函数handleTapAnimation() 时,为什么会出现这些错误?我在代码 sn-p 下方提供了相关截图。
作为参考,我使用 Xcode 11.4.1 作为我的 IDE。
import UIKit
class ViewController: UIViewController {
// Other methods
override func viewDidLoad() {
super.viewDidLoad()
setupLabel()
setupStackView()
//animation
view.addGestureRecognizer(UITapGestureRecognizer(target: self,
action: #selector(handleTapAinmation)))
}
@objc fileprivate func handleTapAnimation() {
print ("Animating")
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
self.titleLabel.transform = CGAffineTransform(translationX: -30, y: 0)
}) { (_) in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.titleLabel.alpha = 0
self.titleLabel.transform =
self.titleLabel.transform.translatedBy(x: 0,y: -200)
})
}
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseOut, animations: {
self.titleLabel.transform = CGAffineTransform(translationX: -30, y: 0)
}) { (_) in
UIView.animate(withDuration: 0.5, delay: 0.5, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
self.bodyLabel.alpha = 0
self.bodyLabel.transform =
self.bodyLabel.transform.translatedBy(x: 0,y: -200)
})
}
}
非常感谢任何帮助。
【问题讨论】:
-
您在花括号上犯了一个错误(在屏幕截图之前的某个时间点)。
-
Ainmation != 动画