I'm implementing a custom pull-to-refresh component.
Create CALayer with a spinner animation, than add this layer to UICollectionView. Layer's speed is zero (self.loaderLayer.speed = 0.0f;
) and layer animation is managed with timeOffset in scrollViewDidScroll:
. Problem goes here, because I also want to show a loader always in the center of pulling space, so I change layer's position in scrollViewDidScroll:
like this:
[self.loaderLayer setPosition:CGPointMake(CGRectGetMidX(scrollView.bounds), scrollView.contentOffset.y / 2)];
But nothing happens with layer position (calling [self.loaderLayer setNeedsDisplay]
doesn't help). I understand that it's because zero speed. And currently I found the way which works (but I don't like that):
self.loaderLayer.speed = 1.0f;
[self.loaderLayer setPosition:CGPointMake(CGRectGetMidX(scrollView.bounds), scrollView.contentOffset.y / 2)];
self.loaderLayer.speed = 0.0f;
How could I change a position for a paused layer right? What am I missing?
speed
to0.0f
causes all animations for that layer to be paused; including positioning. There is probably a different way to implement your "spinner animation pause" than what you're doing, but it's hard to say what that is without seeing the code of how you construct your spinner layer. – Ian MacDonaldsetPosition
is animated and you have animation speed set to zero. So move it without animation. – David Berry