【问题标题】:UIView w/animation not removed after removeFromSuperview()在 removeFromSuperview() 之后未删除带有动画的 UIView
【发布时间】:2017-12-17 18:37:14
【问题描述】:

https://imgur.com/cDyns2l

当我的应用首次打开时,我有一个带有动画的自定义 UIView。

fileprivate func startAnimation() {
    UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
        self.one.transform = CGAffineTransform(scaleX: self.scaleFactor, y: self.scaleFactor)
    }) { (complete) in
        UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
            self.one.transform = CGAffineTransform(scaleX: 1, y: 1)
            self.two.transform = CGAffineTransform(scaleX: self.scaleFactor, y: self.scaleFactor)
        }) { (complete) in
            UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
                self.two.transform = CGAffineTransform(scaleX: 1, y: 1)
                self.three.transform = CGAffineTransform(scaleX: self.scaleFactor, y: self.scaleFactor)
            }) { (complete) in
                UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
                    self.three.transform = CGAffineTransform(scaleX: 1, y: 1)
                    self.four.transform = CGAffineTransform(scaleX: self.scaleFactor, y: self.scaleFactor)
                }) { (complete) in
                    UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
                        self.four.transform = CGAffineTransform(scaleX: 1, y: 1)
                        self.five.transform = CGAffineTransform(scaleX: self.scaleFactor, y: self.scaleFactor)
                    }) { (complete) in
                        UIView.animate(withDuration: self.scaleTime, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseInOut, animations: {
                            self.five.transform = CGAffineTransform(scaleX: 1, y: 1)
                        }) { (complete) in
                            self.startAnimation()
                        }
                    }
                }
            }
        }
    }

}

这样循环,达到我想要的效果。但是,当我从其父视图中删除动画视图时,动画会继续并且不会被删除。

【问题讨论】:

  • 你试过删除动画 view.layer.removeAllAnimations() 吗?

标签: ios swift animation uiview


【解决方案1】:

如果您的目标是 iOS 10 或更高版本,我建议您查看 UIViewPropertyAnimator 以获取可取消动画。动画也可以反转,这对你的加载器很有好处。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2011-10-13
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多