如何为遮罩层设置动画以使其可以擦洗?

时间:2020-06-01 23:53:37

标签: swift calayer

我们可以使用CABasicAnimation轻松地为视图的遮罩层设置动画:

let someMask = CALayer()
someMask.frame = CGRect(x: 0, y: 0, width: w, height: h)
someMask.anchorPoint = CGPoint(x: 0.5, y: 0)
someMask.position = CGPoint(x: w/2, y: 0)
someMask.backgroundColor = UIColor.white.cgColor

someView.layer.mask = someMask

let anim = CABasicAnimation(keyPath: "bounds.size.height")
anim.fillMode = .forwards
anim.isRemovedOnCompletion = false
anim.fromValue = h
anim.toValue = 0
anim.duration = 1

someMask.add(anim, forKey: nil)

但是,如果我们要使动画可擦除,例如在由交互控制器擦除的自定义模态解雇动画中,将忽略蒙版动画。

CATransaction.begin()
CATransaction.setAnimationDuration(1)
someMask.add(anim, forKey: nil) // this is not scrubbed (the animation just executes)
UIView.animate(withDuration: d, animations: {
    // all of these animations, however, can be scrubbed by the interaction controller
})
CATransaction.commit()

如何配置蒙版动画,以便可以由交互控制器在动画中对其进行擦洗?蒙版上的动画正在执行的操作是将其边界高度缩小到0

0 个答案:

没有答案
相关问题