[英]UiView.animateWithDuration Not Animating Swift3
I am trying to animate all view outlets from bottom using below code (The outlets should come from bottom and fill the view within 1 seconds).我正在尝试使用以下代码从底部为所有视图出口设置动画(出口应来自底部并在 1 秒内填充视图)。 However, it doesn't animate and everything is immediately shown no matter how much time I put.
但是,它没有动画,无论我投入多少时间,所有内容都会立即显示。 I noticed following:
我注意到以下内容:
Animation is not happening.动画没有发生。 Component is immediately shown
组件立即显示
override func viewDidAppear(_ animated: Bool) {覆盖 func viewDidAppear(_ 动画:布尔){
super.viewDidAppear(animated); UIView.animate(withDuration: 1, animations: { self.topConstraint.constant = 0; self.imageView.frame.origin.y = 1024; self.view.setNeedsLayout(); })
I figured out the issue myself.我自己想通了这个问题。
super.viewDidAppear(animated);
UIView.animate(withDuration: 1, animations: {
self.topConstraint.constant = 0;
self.view.layoutIfNeeded()
self.imageView.frame.origin.y = 1024;
self.view.setNeedsLayout();
})
}
You need to remove self.imageView.frame.origin.y = 1024;
您需要删除
self.imageView.frame.origin.y = 1024;
, and set self.topConstraint.constant = 1024;
, 并设置
self.topConstraint.constant = 1024;
before animation block动画块前
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.