swift - 使用 Xcode 11.4.1,为什么这些错误显示在动画部分?
问题描述
为什么当我尝试在handleTapAnimation()
内部调用动画函数时会出现这些错误viewDidLoad()
?我在代码片段下方提供了一个相关的屏幕截图。
作为参考,我使用 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)
})
}
}
任何帮助深表感谢。
解决方案
只需复制第 46 行并将其粘贴到 viewdidload() 并将 handleTapAnimation() 函数放入 viewcontroller 类,因为您将它写在 viewcontroller 之外
推荐阅读
- python - 对python字节文字感到困惑
- amazon-web-services - Athena 对布尔列没有显示任何值,使用胶水爬虫创建的表
- salesforce - 每 x 天重复 Salesforce Workflow 操作
- javascript - googleapis npm 模块和 webpack 包错误
- python - wxPython 中的组事件
- java - 格式化日历事件的日期时间对象,从谷歌日历 api 检索
- httpclient - org.apache.http.NoHttpResponseException: 在微服务中请求服务器时目标服务器没有响应
- java - 我正在尝试在文件中写入数组字节,但我不能。(我可以在 FileSystem 中创建这个文件,并且连接正常)。任何帮助表示感谢
- python - 看门狗项目:分配错误前的参考
- php - 故意造成死锁的集成测试 (PHP)