PDA

View Full Version : How to create Animation Graphic for Iphone?




lamfan
Aug 4, 2008, 10:26 AM
Is there any framework can work on it?

I had thinking about using NSTime to set up loading different UIViewImage in every second,

I don't know is that the right way to create animation graphic for iphone.

Any suggestion?



caldwelljason
Aug 5, 2008, 04:41 PM
Use UIImageView for simple animations.

You set the animationImages to an NSArray of UIImage*. Then you set the animationDuration and animationRepeatCount on your UIImageView. Finally, you need to call startAnimating on the UIImageView. That will cause the animation to cycle through your images animationRepeatCount times, or until you call stopAnimating.

That's a very high-level, simple view of how to start out with animation on the iPhone. You can do more interesting things with layers and so forth, but that's a bugger question...;)

jagatnibas
Sep 4, 2008, 09:36 AM
Hi col i tried doing the following

NSArray *images = [NSArray arrayWithObjects:@"groundhog2.jpg",@"noframes.gif"];
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
[imageView setAnimationImages:images];
[imageView setAnimationRepeatCount:2];
//imageView.image = [UIImage imageNamed:@"noframes.gif"];//img;
imageView.center = self.center;
self.picView = imageView;

[imageView release];
[self.picView startAnimating];
[self addSubview:picView];

it crashes, why so ?

should it work on simulator ?

Jagat

robbieduncan
Sep 4, 2008, 09:41 AM
I imagine it crashes because you've set the images to an array of strings, not an array of images.

jagatnibas
Sep 4, 2008, 10:22 AM
i tried the folowing modified code, still it crashes

UIImage* img1 = [UIImage imageNamed:@"groundhog2.jpg"];
UIImage* img2 = [UIImage imageNamed:@"noframes.gif"];

NSArray *images = [NSArray arrayWithObjects:img1,img2];
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 300.0)];
[imageView setAnimationImages:images];
[imageView setAnimationRepeatCount:2];
//imageView.image = [UIImage imageNamed:@"noframes.gif"];//img;
imageView.center = self.center;
self.picView = imageView;
//[imageView startAnimating];
[imageView release];
[self.picView startAnimating];
[self addSubview:picView];

robbieduncan
Sep 4, 2008, 10:26 AM
Well now you are abusing NSArray arrayWithObjects: (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/Reference/Reference.html#//apple_ref/occ/clm/NSArray/arrayWithObjects:). As per the documentation (which I would expect you to use to solve these problems) you must terminate the list of objects with nil.

jagatnibas
Sep 4, 2008, 10:40 AM
Thanks a lot. how could I do this.

anyway, it is working now, though one thing is after animation finished the view becomes black. how would i be animating infinitely ? or else after count finishes, how can i stop on the ending image ?

moreover I am doing this in initframe now. I want to do it on tap on the static image. means, first a static image will display, when i click on that the animation will play and go back to previous static image.

please guide me doing that

thanks and regards

Jagat

robbieduncan
Sep 4, 2008, 10:48 AM
Thanks a lot. how could I do this.

anyway, it is working now, though one thing is after animation finished the view becomes black. how would i be animating infinitely ? or else after count finishes, how can i stop on the ending image ?

moreover I am doing this in initframe now. I want to do it on tap on the static image. means, first a static image will display, when i click on that the animation will play and go back to previous static image.

please guide me doing that

thanks and regards

Jagat

Please read the documentation (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImageView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIImageView/animationRepeatCount). We are not here to research the answers to basic questions clearly covered in the documentation for you. If you can't use the documentation you shouldn't be programming for the platform.