Is there a way to freeze the last frame of my animation in my iphone app? Here's my code so far.
popup.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"picture1.png"],
[UIImage imageNamed:#"picture2.png"],
[UIImage imageNamed:#"picture3.png"],
[UIImage imageNamed:#"picture4.png"],
[UIImage imageNamed:#"picture5.png"],
[UIImage imageNamed:#"picture6.png"],
[UIImage imageNamed:#"picture7.png"], nil];
popup.animationDuration = 1.750567;
popup.animationRepeatCount = 1;
[popup startAnimating];
[self.view addSubview:popup];
When animation stops UIImageView shows UIImage set in its image property. So you should just set it to the last frame of your animation:
popup.image = [UIImage imageNamed:#"picture7.png"];
Related
I have added a UIView, On that UIImageView using UIBuider,
Now I want to apply animation on that imageView, so I'v taken an array of images & adding that
array to imageView through this code
NSArray *animationArray=[[NSArray alloc]init];
animationArray=[NSArray arrayWithObjects:
[UIImage imageNamed:#"rabbit1.png"],
[UIImage imageNamed:#"rabbit2.png"],
[UIImage imageNamed:#"rabbit3.png"],
[UIImage imageNamed:#"rabbit4.png"],
[UIImage imageNamed:#"rabbit5.png"],
[UIImage imageNamed:#"rabbit6.png"],
[UIImage imageNamed:#"rabbit7.png"],
[UIImage imageNamed:#"rabbit8.png"],
[UIImage imageNamed:#"rabbit9.png"],
[UIImage imageNamed:#"rabbit10.png"],
[UIImage imageNamed:#"rabbit11.png"],
[UIImage imageNamed:#"rabbit12.png"],
[UIImage imageNamed:#"rabbit13.png"], nil];
tempImageView.animationImages=animationArray;
tempImageView.animationDuration=2;
tempImageView.animationRepeatCount=0;
[tempImageView startAnimating];
tempImageView is created using UIBuider
But it is not woking, isn't showing anything.
There seems to a bug in the story board auto layout..i found the same no result..
Try it via code this works..
mainImageView = [[UIImageView alloc]init];
NSArray *animationArray = [[NSArray alloc]init];
animationArray = [NSArray arrayWithObjects:[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"],[UIImage imageNamed:#"first.png"],[UIImage imageNamed:#"second.png"], nil]; //add your images here
[mainImageView setFrame:CGRectMake(50,50,100,100)];
mainImageView.animationImages = animationArray; //mainImageView is imageview
mainImageView.animationDuration = 2;
mainImageView.animationRepeatCount = 0;
[mainImageView startAnimating];
[self.view addSubview:mainImageView];
I'm wondering if there's anyway to animate an UIImage.
I know that UIImageViews are possible to animate but is there any way to do it directly in a UIImage.
Maybe with Open GL ES or something?
Or are there any other ways you can animate an MPMediaItemArtwork?
Thanks in advance!
Create a UIImageView and set the property of animationImages to an array of UIImages
Here is an example:
NSArray *animationFrames = [NSArray arrayWithObjects:
[UIImage imageWithName:#"image1.png"],
[UIImage imageWithName:#"image2.png"],
nil];
UIImageView *animatedImageView = [[UIImageView alloc] init];
animatedImageView.animationImages = animationsFrame;
[animatedImageView startAnimating];
If you're targeting iOS 5 you can do this directly in UIImage without the UIImageView using
+(UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration
for example,
[UIImage animatedImagesWithImages:animationFrames duration:10];
If you mean animation with a few images, use this code:
// create the view that will execute our animation
UIImageView* YourImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
// load all the frames of our animation
YourImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"01.gif"],
[UIImage imageNamed:#"02.gif"],
[UIImage imageNamed:#"03.gif"],
[UIImage imageNamed:#"04.gif"],
[UIImage imageNamed:#"05.gif"],
[UIImage imageNamed:#"06.gif"],
[UIImage imageNamed:#"07.gif"],
[UIImage imageNamed:#"08.gif"],
[UIImage imageNamed:#"09.gif"],
[UIImage imageNamed:#"10.gif"],
[UIImage imageNamed:#"11.gif"],
[UIImage imageNamed:#"12.gif"],
[UIImage imageNamed:#"13.gif"],
[UIImage imageNamed:#"14.gif"],
[UIImage imageNamed:#"15.gif"],
[UIImage imageNamed:#"16.gif"],
[UIImage imageNamed:#"17.gif"], nil];
// all frames will execute in 1.75 seconds
YourImageView.animationDuration = 1.75;
// repeat the animation forever
YourImageView.animationRepeatCount = 0;
// start animating
[YourImageView startAnimating];
// add the animation view to the main window
[self.view addSubview:YourImageView];
Source
Check UIImage's +animatedImageWithImages:duration: and +animatedImageNamed:duration:.
From UIImage Class Reference:
Creates and returns an animated image from an existing set of images.
This method loads a series of files by appending a series of numbers to the base file name provided in the name parameter. For example, if the name parameter had ‘image’ as its contents, this method would attempt to load images from files with the names ‘image0’, ‘image1’ and so on all the way up to ‘image1024’. All images included in the animated image should share the same size and scale.
You can use this.
arrayOfImages=[[NSMutableArray alloc]init];
for(int i=1;i<=54;i++)
{
NSString *nameResources=#"haKsequence.png";
NSString *changedString= [NSString stringWithFormat:#"%d", i];
NSString *stringWithoutSpaces = [nameResources stringByReplacingOccurrencesOfString:#"K" withString:changedString];
[arrayOfImages addObject:(id)[UIImage imageNamed:stringWithoutSpaces].CGImage];
}
self.view.userInteractionEnabled=NO;
i1.hidden=YES;
image1=[[UIImageView alloc]init];
image1.backgroundColor=[UIColor clearColor];
image1.frame = button.frame;//i1 is obshaped buttion
[self.view addSubview:image1];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:#"contents"];
animation.calculationMode = kCAAnimationDiscrete;
animation.duration = 1;
animation.values = arrayOfMonkeyImages;
[animation setDelegate:self];
animation.repeatCount=3;
[animation setRemovedOnCompletion:YES];
[image1.layer addAnimation:animation forKey:#"animation"];
Swift 4 version:
let animationImages = [UIImage(named: "image1.png"), UIImage(named: "image2.png")]
imageView.animationImages = animationImages
imageView.animationDuration = 10
imageView.startAnimating()
I'm trying to freeze the last frame of an animation. The following code used to work, however after an update to iOS it no longer works. How can I write this code so that the last image stays on the screen?
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"watermelondrop2.png"],
[UIImage imageNamed:#"watermelondrop4.png"],
[UIImage imageNamed:#"watermelondrop6.png"],
[UIImage imageNamed:#"watermelondrop8.png"],
[UIImage imageNamed:#"watermelondrop10.png"],
[UIImage imageNamed:#"watermelondrop12.png"],
[UIImage imageNamed:#"watermelondrop14.png"],
[UIImage imageNamed:#"watermelondrop15.png"], nil];
animation.animationDuration = .8;
animation.animationRepeatCount = 1;
[animation startAnimating];
[self playwatermelondropsound];
[self.view addSubview:animation];
animation.image = [UIImage imageNamed:#"watermelondrop16.png"];
I spend 40 my minutes to resolve your problem, and it was just so simple:
There are two way you can achieve what you want:
Set the image you want on your screen as default image.
or just do this,
//make your last line to first line.
animation.image = [UIImage imageNamed:#"watermelondrop16.png"];
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"watermelondrop2.png"],
[UIImage imageNamed:#"watermelondrop4.png"],
[UIImage imageNamed:#"watermelondrop6.png"],
[UIImage imageNamed:#"watermelondrop8.png"],
[UIImage imageNamed:#"watermelondrop10.png"],
[UIImage imageNamed:#"watermelondrop12.png"],
[UIImage imageNamed:#"watermelondrop14.png"],
[UIImage imageNamed:#"watermelondrop15.png"], nil];
animation.animationDuration = .8;
animation.animationRepeatCount = 1;
[animation startAnimating];
[self playwatermelondropsound];
[self.view addSubview:animation];
And guess what it'll start working, as I have tested it. :)
[self cleanStance];
NSArray *imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:#"jump1.png"],
[UIImage imageNamed:#"jump2.png"],
nil];
self.player.animationImages = imageArray;
self.player.animationDuration = 0.3;
//self.player.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:self.player];
[self.player startAnimating];
- (void)cleanStance {
[self.player setImage:nil];
self.player.animationImages = nil;
}
This is the example to show the image jumping i thick this may help u
Your code looks fine to me, except when I do it, I usually set the .image property of the UIImageView BEFORE I tell the UIImageView to start animating. Also, add [UIImage imageNamed:#"watermelondrop16.png"] to the end of your .animationImages array. Maybe that will fix your problem. Hope that Helps!
Here i need to created the video from number of images but i also include a audio also i also included the Airplaycode
I think you want to create a animated images(series of images) do one thing play audio in background or on button click and for animated images try this:-
animationView = [[UIImageView alloc] initWithFrame:CGRectMake(157,354, 45, 100)] ;
animationView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.jpg"],
[UIImage imageNamed:#"image2.jpg"],
[UIImage imageNamed:#"image3.jpg"],
[UIImage imageNamed:#"image4.jpg"],[UIImage imageNamed:#"image7.jpg"],
[UIImage imageNamed:#"image5.jpg"],
[UIImage imageNamed:#"image6.jpg"], nil];
animationView.animationDuration = .65;
animationView.animationRepeatCount = 0;
[animationView startAnimating];
[self.view addSubview:animationView];
[animationView release];
can we use a gif image as a background?
i want to set an gif image as a background, like some birds flying ....
can we use gif image to set as background.???
if yes than how?
thanks and regards
Yes you can - I assume you want an animated gif?
It's the same CSS rule as a static background.
body {
background: url(animated.gif);
}
Here, i got the solution.
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"default1.jpg"],
[UIImage imageNamed:#"default2.jpg"],
[UIImage imageNamed:#"default3.jpg"],
[UIImage imageNamed:#"default4.jpg"],
[UIImage imageNamed:#"default5.jpg"],
[UIImage imageNamed:#"default6.jpg"],
[UIImage imageNamed:#"default7.jpg"],
[UIImage imageNamed:#"default8.jpg"],
[UIImage imageNamed:#"default9.jpg"],
[UIImage imageNamed:#"default10.jpg"],
[UIImage imageNamed:#"default11.jpg"],
[UIImage imageNamed:#"default12.jpg"],
[UIImage imageNamed:#"default13.jpg"],
[UIImage imageNamed:#"default14.jpg"],
[UIImage imageNamed:#"default15.jpg"], nil];
animatedImageView.animationDuration = 3.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];