从带动画的SuperView中删除UIVIew时,可以使用以下方法:
UIView.animate
方法,将动画时间设置为0,然后在动画结束时调用removeFromSuperview
方法。UIView.animate(withDuration: 0, animations: {
view.alpha = 0
}, completion: { _ in
view.removeFromSuperview()
})
CATransaction
类来设置动画时间为0,然后在动画结束时调用removeFromSuperview
方法。CATransaction.begin()
CATransaction.setAnimationDuration(0)
view.layer.removeAllAnimations()
view.removeFromSuperview()
CATransaction.commit()
UIView.performWithoutAnimation
方法来暂时禁用动画,然后调用removeFromSuperview
方法。UIView.performWithoutAnimation {
view.removeFromSuperview()
}
以上方法都可以在带动画的SuperView中删除UIVIew,并且不会影响到其他子视图的动画效果。
领取专属 10元无门槛券
手把手带您无忧上云