Staggered iOS animation - iphone

I would like to perform a simple animation on a series of UIImageViews in my app. I have a grid of images that I want to fade in. I can make it so that the next image starts its animation after the previous one completes, like so:
|--------animation1--------|
|--------animation2--------|
|--------animation3--------|
Which I accomplish with code like this:
- (void)loadOtherIcon;
{
UIImageView *icon = [icons objectAtIndex:iconCount];
[UIView animateWithDuration:0.5 delay:0.0 options:nil animations:^{
icon.alpha = 1;
} completion:^(BOOL finished){
if (iconCount < icons.count - 1) {
[self loadOtherIcon];
}
}];
}
But I was hoping to stagger them, like this:
|--------animation1--------|
|--------animation2--------|
|--------animation3--------|
Any suggestions?

Start each of the animations at the same time, but use an increasing "delay" amount. Currently, you're setting it to 0.0.

Related

IOS uiview brightness change

I have two UIViews on my screen. I need to do the following:
If I increase the first view's alpha value, the second UIView alpha value should decrease. The reverse is also true.
Please show me an example of how to do this.
Perhaps something like this can help you to start:
// Displays second view and hide first view.
[UIView animateWithDuration:0.5
delay:0.0
options: 0
animations:^{
myFirstView.alpha = 0.0f;
mySecondView.alpha = 1.0f;
}
completion:^(BOOL finished){
NSLog(#"Done!");
}
];
The reverse case can be produced by reversing the alpha values.

Interrupt completion block based animations to perform separate animations

I am using block based animations to simulate dealing cards as an intro animation for a game. The animation works great unless the user causes a segue to fire DURING the animation, where we perform additional animations in order to get the effect a "sliding" transition from source to destination view controller. What happens now is the cards that have already been "dealt" slide off screen appropriately, and if there are cards that have not been dealt, it deals it in the middle of the transition and then the card disappears when the destination view controller is pushed. It's very ugly.
I have tried 'view.layer removeAllAnimations' which didn't help (I did import quartzcore). What I want to do is cancel the pending animations in the completion blocks, and simply perform the segue animations.
Here's the "dealing" code:
[UIView animateWithDuration:0.20f
delay:0.20f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
_fiveOfHearts.center = CGPointMake(90, 198);
_fiveOfHearts.transform = fiveOfHeartsTransform;
}
completion:^(BOOL finished)
{[UIView transitionWithView:_fiveOfHearts duration:0.20f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
_fiveOfHearts.image = [UIImage imageNamed:#"52"];
}completion:nil];
[UIView animateWithDuration:0.30f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
_jackOfHearts.center = CGPointMake(128, 196);
_jackOfHearts.transform = jackfHeartsTransform;
}
completion:^(BOOL finished)
{[UIView transitionWithView:_jackOfHearts duration:0.40f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
_jackOfHearts.image = [UIImage imageNamed:#"112"];
}completion:nil];
[UIView animateWithDuration:0.30f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
_aceOfHearts.center = CGPointMake(162, 196);
_aceOfHearts.transform = aceOfHeartsTransform;
}
completion: ... and so on.
The segue code looks something like:
for (UIView *iv in src.view.subviews) {
if (iv.tag != 99999) {
[UIView animateWithDuration:0.5f animations:^{iv.center = CGPointMake(iv.center.x - 600, iv.center.y);}];
}
}
You could add a global BOOL say hasUserSkippedOn once the user presses to move on set it to YES and then every time you hit a completion block check if _hasUserSkipped is still YES then do not proform any more. Normally on blocks it has a default end bool but I am not too sure if animations blocks have the end bool.

How to impelment Phone call animation like iPhone's default Phone application does?

My application has VOIP calling. In that I want to implement animation like iPhone's default Phone application does when User Clicks on Call button on dial Pad and animation that is done on End call button.
I have researched alot about this but haven't find anything yet. Any help will be appreciated on this topic.
Right now I have implemented scaling animation like below:
- (void)animateFadingOut{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[self performSelector:#selector(push) withObject:nil afterDelay:0.35];
self.view.transform = CGAffineTransformMakeScale(0.00, 0.00);
//set transformation
[UIView commitAnimations];
}
- (void)push
{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
// push navigation controloller
CallViewController *objCallViewController = [[CallViewController alloc] initWithNibName:#"CallViewController_iPhone" bundle:nil];
[self setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:objCallViewController animated:NO];
[objCallViewController release];
[self setHidesBottomBarWhenPushed:NO];
[[AppDelegate shared] setTabHidden:TRUE];
}
But It is not giving me exact animation that default Phone application has
Here is what I might try if I was trying to create animations.
CGRect movementFrame = self.view.frame;
//Make position and size changes as needed to frame
movementFrame.origin.x = 0;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
/*
Animation you want to commit go here
Apply movementFrame info to the frame
of the item we want to animate
*/
//If you wanted a fade
self.view.alpha = !self.view.alpha //Simply says I want the reverse.
self.view.frame = movementFrame;
//Example of what you could do.
self.view.transform =CGAffineTransformMakeScale(1.00, 1.00);
} completion:^(BOOL finished) {
//Things that could happen once the animation is finished
[self push];
}];
This has not been tested for your case. Therefore I am also not sure if it will help you, but hopefully it will. Good luck to you.
*Edit*
So I reviewed the animation on an iPhone and it appears to me to be a series of animations happening at once.
You have what I presume to be the UIActionSheet animating down.
The top section overlay sliding up its y-axis.
Then you have, which I haven't mastered yet, a split in the back view that animates its x-axis in opposite directions which cause the split.
Finally you have the new view scale up to take frame for the effect.
I can't say 100% this how they have done it, however if I was going to attempt to recreate this, I would likely start here.
Hello there so after just quickly coming up with an animation I got pretty close it could use some tweaks.
It took me three views to do a
topView, bottomView, and backView.
Also took into account the view that you would be loading in. viewToLoadIn
`-(void)animation{
CGRect topMovementFrame = self.topView.frame; //Set dummy frame to modify
CGRect bottomViewFrame = self.bottomview.frame;
topMovementFrame.origin.y = 0 - self.topView.frame.size.height; //modify frame's yAxis so that the frame sits above the screen.
bottomViewFrame.origin.y = self.view.frame.size.height; //modify frame's yAxis to the it will sit at the bottom of the screen.
[self.viewToLoadIn setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//Animation
self.topView.frame = topMovementFrame; //Commit animations
self.bottomview.frame = bottomViewFrame;
self.backView.alpha = !self.backView.alpha;
self.backView.transform = CGAffineTransformMakeScale(100, 100);
self.viewToLoadIn.transform = CGAffineTransformMakeScale(2.0, 3.0);
*MAGIC*
} completion:^(BOOL finished) {
//Completion
//Clean up your views that you are done with here.
}];
}`
So then When they pressed the button I had setup this animation would happen.
Also at first I thought that the setup might contain a UIActionStyleSheet. which it still might but this is a pretty handy built in functionality. But the fact that you can interact with the screen lead me to think a custom view. It would be easier in my opinion.
I hope this helps you even if it just a little bit.
Take care ^^

animateWithDuration: corrupts smooth progressbar increment

In one of my views i need to animate frame property of a UIImageView and while doing it i want to show a progress bar(UIProgressView) in the title view of the navigation bar.The problem is the if i comment out the following animation blocks the progress bar is updated as expected smoothly.On the other hand due to the following animation the progress bar stops in severals places and carries incrementing again.
//add message bubble
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
animationBubbleImageView.alpha = 1;
}
completion:^(BOOL finished)
{
[self removeAutoCorrectionAndHighlight];
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionAllowUserInteraction
animations:^
{
CGRect bubbleFrame = CGRectMake(animationBubbleImageView.frame.origin.x,
animationBubbleImageView.frame.origin.y,
bubbleSize.width,
bubbleSize.height);
[animationBubbleImageView setFrame:bubbleFrame];
messageLabel.alpha = 1;
}
completion:^(BOOL finished)
{
[self sendSubviewToBack:textView];
[self.delegate moveBubbleToTableCell];
}];
}];
animation blocks do not block the main thread but what coudl be the reason of unsmooth beahviout of th progress view ?
UPDATE: What i want to achive is the MessagesApp bubble animation in IOS.While the typed message becomes a bubble and flies to its place the progress bar should increment slowly.
If i try the same thing withou animation progressbar increments normal.
Try putting the progress bar animation in the same animation as the bubble animation. Or put them all into an animation group.
Have you tried Instruments to see what's happening?
Wild guess: you can also check whether the two views inadvertently overlap.
If feasible you can also try to group together the animations, as suggested by "Dad".
Best, Akos

our fade animation freezes button & slider controls

I have a simple photo transition on an iPad program that precludes operator interaction during the transition. The 2 photos are approx 200kb each and the fade is by changing their alphas with the following code;
-(void)photoLoopAnimation
{
// FADE block animation method - THIS contains the basic animation features
[UIView animateWithDuration:5.2 delay:delaySeconds
options:UIViewAnimationOptionTransitionNone
animations:^{
viewTop.alpha = 0.0;
viewBottom.alpha = 1.0;
}
completion:^(BOOL finished) { // remove both views & loop
[viewTop removeFromSuperview];
[viewBottom removeFromSuperview];
[viewTop release];
[viewBottom release];
[self photoLoop];
//[self performSelectorInBackground:(#selector(photoLoop)) withObject:nil];
}];
}
My understanding is that the animation block works as a background thread (task?), & shouldn't lock control of the app while it is executing. Can anyone offer any incite? (insight)
Thanks,
CPL
Try adding the UIViewAnimationOptionAllowUserInteraction option if your controls are being animated.