简体   繁体   English

UiView.animateWithDuration 不为 Swift3 设置动画

[英]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:我注意到以下内容:

  • Duration is not respected不尊重持续时间
  • Not even delay is respected连延迟都不尊重
  • 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM