I require to move 5 images across the screen and do transitional effects, such as rotate -> when rotate animation complete: move (when move complete: then repeat process)
I can get 1 image to do this, it works fine.
The problem I have is I need to do it for 5 images; the requirements are that all the images (or imageViews) need the animations to run at the same time.
I use a custom object which has a UIImageView inside it
-(void)stopRepeatingAnimationForView:(UIView *)view
{
self.enableRepeatingAnimation = NO;
[view.layer removeAllAnimations];
}
- (void)startRepeatingAnimationForView:(UIView *)view
{
self.enableRepeatingAnimation = YES;
[self repeatingAnimationForView:view];
}
- (void)repeatingAnimationForView:(UIView *)view
{
//VICAirplane *planeObj = [self.airplanes objectAtIndex:0];
for (VICAirplane *planeObj in self.airplanes) {
[UIView animateWithDuration:3
delay:1
options:UIViewAnimationOptionCurveLinear
animations:^{
planeObj.imageView.transform = CGAffineTransformRotate(planeObj.imageView.transform, planeObj.angleToRotate);
} completion:^(BOOL finished) {
if (finished==YES) {
[UIView animateWithDuration:5
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
planeObj.imageView.center = planeObj.rotateToLocation;
} completion:^(BOOL finished) {
if (finished==YES) {
if ( self.enableRepeatingAnimation )
{
CGPoint rotateToLocation = [self generateRandomLocation];
planeObj.rotateToLocation = rotateToLocation;
[self performSelector:@selector(repeatingAnimationForView:) withObject:view afterDelay:0];
}
}
}];
}
}];
} // next
}
If remove the loop through the array or simply make it 1 length array the animation works fine.
But if I add multiple the animations are all the same time, and they start losing the finished state and end up doing a lot of mess.
What I'd like to do is:
- Loop through my 5 images
- Perform my rotate -> move -> repeat (forever) animation on each image
But I'm not sure how to make it work for multiple uiimageviews stored in an array
Is there a way to do this?