我需要将我的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();发布于 2018-10-10 21:30:14
我的代码证明您的代码没有问题。如果它崩溃了,肯定还有其他原因。
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();
}
}https://stackoverflow.com/questions/52739074
复制相似问题