我需要对CAReplicatorLayer对象进行动画处理,最多增加50个像素。
我实现了将CAReplicatorLayer帧更新为50像素的效果,但是动画却没有实现。
这是我的代码。
CATransaction.begin();
CATransaction.setAnimationDuration(2.0)
self.rippleLayer.position = self.imgLogo.center //rippleLayer is my CAReplicatorLayer object and self.imgLogo.center is like 50 pixels up for refernce.
CATransaction.setDisableActions(true)
CATransaction.commit();
答案 0 :(得分:1)
我的代码证明您的代码没有问题。如果它崩溃了,肯定还有其他原因。
var rippleLayer: CAReplicatorLayer!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
rippleLayer = CAReplicatorLayer.init()
rippleLayer.frame = CGRect.init(x: 0, y: 0, width: 100, height: 100)
rippleLayer.backgroundColor = UIColor.red.cgColor
self.view.layer.addSublayer(rippleLayer)
Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false) { _ in
CATransaction.begin();
CATransaction.setAnimationDuration(2.0)
self.rippleLayer.position = self.view.center //rippleLayer is my CAReplicatorLayer object and self.imgLogo.center is like 50 pixels up for refernce.
CATransaction.setDisableActions(true)
CATransaction.commit();
}
}