I am trying to create custom activity indicator it has two images one image will be static (in the background) and another image will be in the front, it has to move left, right, top and bottom (just to give animation feel). I tried to use the following code (Its wrong one). Can anyone help me, how to do animation
UIImage *statusImage = [UIImage imageNamed:@"image1.png"];
UIImageView *activityImageView = [[UIImageView alloc]
initWithImage:statusImage];
//Add more images which will be used for the animation
activityImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.png"],
[UIImage imageNamed:@"image2.png"], nil];
//Set the duration of the animation (play with it
//until it looks nice for you)
activityImageView.animationDuration = 7;
activityImageView.frame = CGRectMake(
self.view.frame.size.width/2
-statusImage.size.width/3,
self.view.frame.size.height/2
-statusImage.size.height/3,
statusImage.size.width/3,
statusImage.size.height/3);
//Start the animation
[activityImageView startAnimating];
A UIImageView can animate through the images, kind of like a gif. What you want can be achieved much more elegantly using CAAnimation. This code gives shows you an animation to left and right:
Create a CAAnimation for the layer which you want to move at each corners and add it as a positioning object. Hope it helps