【问题标题】:UIView animate finished called before animation finished在动画完成之前调用 UIView 动画完成
【发布时间】:2017-01-02 12:48:41
【问题描述】:

我正在尝试创建一个animation,其中视图首先向下动画,然后从超级视图中删除,我的代码如下所示:

UIView.animate(withDuration: 5, delay: 5, options: .allowAnimatedContent, animations: {
        NSLog("Animation started")
        self.scrollView.setContentOffset(CGPoint(x:0,y:-500), animated: true)

    }, completion: {(finished: Bool) in
        if finished{
            NSLog("Animation stopped")
            self.view.removeFromSuperview()
        }
    })

由于持续时间是5,所以应该在 5 秒后调用完成,否则我错了?

在这种情况下,finished 在动画完成并删除视图之前被调用,并且动画显然根本没有显示,因为视图已被删除。

这里是NSLog

2017-01-02 17:39:37.649 [1581:26706] Animation started
2017-01-02 17:39:37.652 [1581:26706] Animation stopped

finished 在不到一秒的时间内被调用

【问题讨论】:

    标签: ios animation uiview swift3


    【解决方案1】:

    尝试将setContentOffset:函数animated设置为false

    UIView.animate(withDuration: 5, delay: 5, options: .allowAnimatedContent, animations: {
        NSLog("Animation started")
        self.scrollView.setContentOffset(CGPoint(x:0,y:-500), animated: false)
    }, completion: {(finished: Bool) in
        if finished{
            NSLog("Animation stopped")
            self.view.removeFromSuperview()
        }
    })
    

    【讨论】:

      猜你喜欢
      • 2018-07-14
      • 2011-03-11
      • 1970-01-01
      • 2014-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多