Update:
There is no problem here. Turns out I was re-adding the animation every time I moved the point. Was else where in the code and I just totally glossed over it. Please ignore this question.
end update
I have a UIView which is just acting as a container for a UIImageView and a CAShaperLayer. The shape layer is drawing a circle and I have added a path animation to that shape layer to make it pulse. I want to be able to pulse the circle and move the container view at the same time using the center property of the UIView. However, when I set the center property on the container UIView, the pulse animation restarts from it's beginning no matter where it is at in it's animation.
How do I prevent the pulse animation from restarting?
Pulse animation:
CGRect startRect = CGRectMake(-10 + (self.bounds.size.width / 2),
-10 + (self.bounds.size.height / 2),
20,
20);
CGMutablePathRef fromPath = CGPathCreateMutable();
CGPathAddEllipseInRect(fromPath, NULL, startRect);
CGRect endRect = CGRectMake(-20 + (self.bounds.size.width / 2),
-20 + (self.bounds.size.height / 2),
40,
40);
CGMutablePathRef toPath = CGPathCreateMutable();
CGPathAddEllipseInRect(toPath, NULL, endRect);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.fromValue = (id)fromPath;
an开发者_高级运维imation.toValue = (id)toPath;
CGPathRelease(fromPath);
CGPathRelease(toPath);
animation.duration = 2.0f;
animation.repeatCount = HUGE_VALF;
[self.myCircleLayer addAnimation:animation forKey:self.pathAnimationKey];
I move the container view by doing:
self.myContainerView.center = newPoint;
See the update above. Turns out there was no problem here.
精彩评论