UIView动画立即完成

问题描述 投票:0回答:1

所以我一直在从事一个个人项目,在这里我想应用所学到的一切,但是遇到了这个问题。

我已将此问题简化为这个简单的应用程序。

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

}

@IBAction func button(_ sender: UIButton) {
    let nextVC = storyboard?.instantiateViewController(withIdentifier: "nextVC") as! SecondViewController
    nextVC.modalPresentationStyle = .fullScreen
    present(nextVC, animated: true)
}

}

但是,当我使用上述按钮更改视图时,已将其设置为在加载时在下面进行动画处理,但是在加载时,它自动处于动画的最后阶段

import UIKit

class SecondViewController: UIViewController {

@IBOutlet weak var loadingImageView: UIImageView!
override func viewDidLoad() {
    super.viewDidLoad()

    UIView.animate(withDuration: 10, animations: {
                   self.loadingImageView.transform = CGAffineTransform(translationX: 0, y: 400)
               }) { (_) in
                   print("Animation has been done")
           }
}
}

任何建议将不胜感激。 :)

ios swift uiviewanimation uiviewanimationtransition
1个回答
0
投票

如果将动画移到viewWillAppear或viewDidAppear上,如@imike建议那样不起作用,请尝试在“ loadingImageView”上使用过渡,而不是“ animate”

 UIView.transition(with: self.loadingImageView,
                     duration: 10,
                     options: [. curveEaseInOut],
                     animations: {

                       self.loadingImageView.transform = CGAffineTransform(translationX: 0, y: 400)
   },
                     completion: nil)
© www.soinside.com 2019 - 2024. All rights reserved.