所以我一直在从事一个个人项目,在这里我想运用所学到的一切,但是遇到了这个问题。
我已将此问题简化为这个简单的应用程序。
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")
}
}
}
任何建议将不胜感激。 :)
答案 0 :(得分:0)
如果像@imike建议的那样将动画移动到viewWillAppear或viewDidAppear无效,请尝试在“ loadingImageView”而非“ animate”上使用过渡
UIView.transition(with: self.loadingImageView,
duration: 10,
options: [. curveEaseInOut],
animations: {
self.loadingImageView.transform = CGAffineTransform(translationX: 0, y: 400)
},
completion: nil)