在RemoveFromSuperview()之后没有移除动画的UIView

时间:2017-12-17 18:37:15

标签: ios swift animation uiview

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()
                        }
                    }
                }
            }
        }
    }

}

这循环并实现我想要的效果。但是,当我从其超级视图中删除我的动画视图时,动画会继续,并且不会被删除。

1 个答案:

答案 0 :(得分:0)

如果您的目标是iOS 10或更高版本,我建议您查看UIViewPropertyAnimator以获取可取消的动画。动画也可以反转,这对你的装载机来说很不错。