【问题标题】:Using Xcode 11.4.1, Why do these errors show in the animation part?使用 Xcode 11.4.1,为什么这些错误显示在动画部分?
【发布时间】: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 != 动画

标签: swift xcode uikit


【解决方案1】:

只需复制第 46 行并将其粘贴到 viewdidload() 并将 handleTapAnimation() 函数放入 viewcontroller 类,因为您将它写在 viewcontroller 之外,就像 igess 一样

【讨论】:

    猜你喜欢
    • 2016-05-21
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 2018-02-06
    • 2017-11-25
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多