Moving 2 images sequentially across the screen in IOS - ios

I have several images that I want to move sequentially, across the screen, each with a specific delay. I have animated the first image like this:
[UIView animateWithDuration:0.5f
animations:^{
image1.center = CGPointMake(image1.center.x + 10.0f, image1.center.y);
}
completion:nil];
Now I want to move image2 behind image 1. Do I have to add a delay for image2? I mean, I want image2 to follow image1 in moving across the screen. How do I do this?
P.S: The above code moves image1 from left to right, across the screen.

Put the animation method (
animateWithDuration:delay:options:animations:completion:) in the completion block of the first animation. Add whatever delay you want (the delay will be between the end of the first animation and the start of the second).

Related

Animating slide show in iOS

Anybody have any idea how this is done?
http://youtu.be/r_cII4_aq_A
In general, the idea is awesome, but I would like to know how to do each specific thing. In the video, the pages are being swiped too fast so you can't see, but as you transition from one page to the next, each pixel smoothly transitions to it's new color. Also, it's really cool how the icon gets smaller to a minimum size as you transition away from a screen.
Maybe there's some 3rd party library that provides a protocol and it's relatively easy to implement, but I can't find it. If there's not, I'm thinking it's just one view controller with many views side by side and as you drag your finger, it calculates where each view needs to be..and what color every pixel needs to be.
I imagine you already have it by now. But in case you still have any doubts, I made gist that does the animation: https://gist.github.com/mnmaraes/9536364
Anyways, have fun.
It's a fade animation, so:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
_backgroundImageView.image = nextImage;
} completion:nil];
should do the trick for the background part.
For the foreground/icon part you can animate the transform to scale and translate the views as they slide in and out.

Receive user interactions wheel animation

UI animations are great, very easy to use, and are used allot. The only one problem I have with it is that while the animation is moving, the view in not receiving any user interaction.
For example, if a have a UIButton that animates every time it's shown, but the user will not be able to click on it until the animation is over.
//This is a UIButton:
- (void)animationApear
{
CGRect frameSelf = self.frame;
frameSelf.origin.y -= frameSelf.size.height;
[UIView animateWithDuration:1.0 delay:0
usingSpringWithDamping:0.8 initialSpringVelocity:0
options:0
animations:^{
[self setFrame:frameSelf];
} completion:nil];
}
Is there any way to deal with this issue?
Thanks!
You need to supply the option UIViewAnimationOptionAllowUserInteraction.
Also, depending on your view architecture, if the button is within the animated view, or a subview thereof, then the actual location of the button isn't moving. Only the presentation layer of the button is moving, so that is why the button may not be receiving taps. A good test is to tap where the button was when the animation started (and make sure the option UIViewAnimationOptionAllowUserInteraction is on) to see if it is still receiving taps.
On solution, when you actually need to animate buttons, is to make repeated short transforms (CGAffineTransforms, for example) and have those movements in aggregate, create the visual effect of the animation. Though in this case the button itself will move, rather than simply it's presentation.

How to add pop up image animation on screen

I'm going to make a quiz game where user will have to pick correct answer from 4 options.Those options will be image format.I want those rectangular images will appear on screen on by one by Pop Up animation.
Can you please tell me how can i add a popup animation on iPhone App?
NB: The pop up animation should be like Pop Up transition in Keynote.I mean after Pop Up it will vibrate a little bit back and forth.
Check this SO link
You can tinker with the values depending on how you want your animation.
//Set default frame for all 4 images.
[UIView animateWithDuration:0.5 animations:^{
//set frame for first image
} completion:^(BOOL finished) {
//this block will call after first animation is done.so after that animate 2nd image . do same for all 4 image.
}];
maybe this will help you.

Setting the previous image right before calling transitionWithView

I have a placeholder UIImageView (loaded from a .xib) which I want to load with a picture of the back of a card and then flip to the front image.
[cardView setImage:backCardImage];
[UIView transitionWithView:cardView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[cardView setImage:frontCardImage];
}
completion:NULL];
The problem is that the initial image it starts with is not backCardImage, instead, it uses the no image (i.e. blank image) from my .xib file. If I had the backCardImage loaded in the .xib and only call transitionWithView, I believe it would work properly, but I would really like to have the two calls (setImage, and transitionWithView) in the same method. Is there any way to do this? Do I need to call something between the two?
I tried using UIViewAnimationOptionBeginFromCurrentState, but that doesn't work either.
The cardView won't draw, even if you put in setNeedsDisplay, until the next drawing cycle, so you need to set that image in another method first, or move the animation to another method, and call it with performSelector:withObject:afterDelay:. Even a delay of 0 will work. I don't think the animation looks very good though, because you only see the back image for an instant before the flip (a delay of .1 or .2 seconds looks better I think). Why not set the back image earlier? What's the purpose of a placeholder image in this context?

UIImageView Animation decreasing Width

I am developing an application which needs to decrease the width of imageview to 0 from 320 in a 1hour time. for this i am using following code
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3600];
newRect.size.width = 0;
imgView.frame = newRect;
[UIView commitAnimations];
it is works fine if we stay in same view controller,after animation starts if the user navigate to some other viewcontoller, How to handle the animation.
Along with this i have one more issue- during the animation the image in imageview is looks like shrink as throughout the animation i am using same image ,So i want to change the image in imageView during the animation How can i achieve this.
Is there any other way to do this apart form the animation.
Any Help is Appreciated.
The life cycle of the controllers and views will not allow you to do this so simply. The objects you are using can and will be deallocated by the system if they are not currently needed anymore, so the animation you started is essentially discarded with it.
You will have to store the progress of your animation somewhere, e. g. in a file or a CoreData database to have it persistent across the instantiations of that view. Depending on the exact situation, it might be sufficient to store the start time of the animation once it begins. Then, in viewWillAppear you could load it and calculate how much progress into that one hour has been made and start a new animation from that point. To the user it would appear as if the animation had proceeded in the background.

Resources