Reputation: 11
i have a gif image and i want to put it in my iphone game background, the image is a moving scenery but when i put in my background its not moving ..How can i keep my background moving like the gif image?
Upvotes: 0
Views: 1128
Reputation: 9740
FOr that you have to use the imageview and set its frame as background view.
Insert all your images used for creating GIF in Resource folder
Then use the following code
UIImageView *imgBackView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
NSArray *myImages = [NSArray arrayWithObjects:@"1.png",@"2.png",@3.png"@4.png", nil];
imgBackView.animationImages = myImages;
imgBackView.animationDuration = 0.5;// OR WHATEVER TIME YOU WANT
imgBackView.animationRepeatCount = 0; // 0 = loops forever
[imgBackView startAnimating];
[self.view addSubview:imgBackView];
[imgBackView release];
hAPPY iCODING...
Upvotes: 4
Reputation: 4963
As far as I know, animated gifs does not work in iPhone. However it is possible to have the same effect using animationImages property of UIImageView. Instead of setting single image, you can set array of UIImages as animationImages of the view. Then you can start the animation any time by calling startAnimating method.
Of course to have an array of images, you will have to extract the frames of the animated gif as different images and add them to your resources.
Upvotes: 0