Как оживить обновление позиции CAReplicatorLayer в swift? - PullRequest
0 голосов
/ 10 октября 2018

Мне нужно анимировать мой объект 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();

1 Ответ

0 голосов
/ 10 октября 2018

Мой код доказывает, что у вашего кода нет проблем.Если он разбился, должны быть и другие причины.

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