I'm trying to animate the same images in a different position like this:
for (int i = 0; i == 3; i++) {
UIImageView *imageToAnimate = [[UIImageView alloc] initWithFrame: imageFrameTwo];
[imageToAnimate setImage: [UIImage imageNamed: imageTwo]];
CGPoint point0 = imageTwoImage.layer.position;
CGPoint point1 = { point0.x + 10*i, point0.y - 10*i + 50};
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"position.y"];
anim.fromValue = @(point0.y);
anim.toValue = @(point1.y);
anim.duration = 15.0f;
anim.repeatCount = HUGE_VALF;
anim.cumulative = NO;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// First we update the model layer's property.
imageToAnimate.layer.position = point1;
// Now we attach the animation.
[imageToAnimate.layer addAnimation:anim forKey:@"position.y"];
[theView addSubview:imageToAnimate];
}
But nothing happens. Without cycle it works well. Am I doing something wrong?
I won't go into details but you can try using animation blocks. 0 and 100 are the origin points. Also, make sure you are not using autoLayout, you should either disable it, or animate using autolayout constraints instead of frame changes.
For example, to animate on x axis you just need to have a different x value in the
The line inside the animation block should slide your view to right by 100 pixels now.