ios - UIView 动画瞬间完成
问题描述
所以我一直在做一个个人项目,我想应用我学到的所有东西,但是我遇到了这个问题。
我已将此问题简化为这个简单的应用程序。
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")
}
}
}
任何建议将被认真考虑。:)
解决方案
如果像@imike 建议的那样将动画移动到 viewWillAppear 或 viewDidAppear 不起作用,请尝试在“loadingImageView”上使用过渡而不是“动画”
UIView.transition(with: self.loadingImageView,
duration: 10,
options: [. curveEaseInOut],
animations: {
self.loadingImageView.transform = CGAffineTransform(translationX: 0, y: 400)
},
completion: nil)
推荐阅读
- python - 使用 ndimage.interpolation.affine_transform 进行矩阵转换
- haskell - 这个 Haskell 代码在多大程度上满足了这个规范?
- php - 统计一个数据表并对其求和,并用默认值填充一个空数据
- d3.js - D3.js +华夫饼图+根据数据在华夫饼图中部分填充圆形/矩形
- html - CSS/HTML Bootstrap 4 页脚 - 悬停
- sql - 如何将n行转换为具有多列的单行
- icons - xpages 视图面板显示计算图标
- scala - spark禁用对引号的支持
- r - 基于站点聚合具有 NA 值的数据
- wordpress - Wordpress:如果自定义字段包含页面 ID,则迭代父页面