使用Xcode 11.4.1,为什么这些错误会显示在动画部分?

时间:2020-05-30 17:23:37

标签: swift xcode uikit

当我尝试在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)

      })
    }
  }

Error Photo

我们非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

只需复制第46行并将其粘贴到viewdidload() 并将handleTapAnimation()函数放到viewcontroller类中,因为您将它作为iguess编写在viewcontroller之外