-2

I don't know how to make an animation, or how I would put that into Xcode. Can someone just give me a little background info on this?

adamcircle
  • 694
  • 1
  • 10
  • 26

2 Answers2

5
NSArray *animationArray = [NSArray arrayWithObjects:[UIImage imageNamed@"firstImage",[UIImage imageNamed@"secondImage",nil];  //add as many as you want

Now you need an imageview to set the animation to:

self.myImageView.animationImages =animationArray;
self.myImageView.animationDuration = 3;
self.myImageView.animationRepeatCount = -1; //keeps going infinitely

[self.myImageView startAnimating];
Makleesh
  • 988
  • 10
  • 15
0

I am guessing that what you want to do is to create an animated image, rather than animate a view transition... Here is a little background on two ways of creating an animation for iOS.

First option: Create an array of Images (UIImage), then use the startAnimating method. Something like this:

imageView.image = yourLastImage;  
// Do this first so that after the animation is complete the image view till show your last image.

NSArray * imageArray  = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"image1.png"],  
[UIImage imageNamed:@"image2.png"],
[UIImage imageNamed:@"image3.png"],                         
[UIImage imageNamed:@"image4.png"],
nil]; 

// Note: here you may instead want to use something like [UIImage imageWithContentsOfFile:[self localImagePath:NO]] instead depending upon your targeted iOS version.



UIImageView * animatedImageView = [[UIImageView alloc] initWithFrame:
        CGRectMake(100, 125, 150, 130)];
    animatedImageView.animationImages = imageArray;
    animatedImageView.animationDuration = 1.1;
        myAnimation.animationRepeatCount = 1;
    animatedImageView.contentMode = UIViewContentModeBottomLeft;

    [self.view addSubview:animatedImageView];
    [animatedImageView startAnimating];

Second Option: (for iOS 4 and later) You can use block-based methods. Here is a link to a reference article for this here on StackOverflow.

What are block-based animation methods in iPhone OS 4.0?

Also you may want to take a look at the documentation that Apple provides relating to Core Animation:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html#//apple_ref/doc/uid/TP40006085-SW1

Community
  • 1
  • 1
ciara staggs
  • 329
  • 2
  • 7