Animating a View Like This Example - iphone

I am facing a problem when trying to animate a view. When the user clicks on the advanced search button, it is navigating this view and the animation starts, but it is not correct. How can I animate a view when the user clicks on the advanced search button?
(I want to make this type of animation : )
http://d2o0t5hpnwv4c1.cloudfront.net/041_TopPanelWithJquery/demo/index.html
Are there any good tutorials that will help me in this matter?
Some existing code from a comment
AddSearchView.frame = CGRectMake(10, 65, 310, 148);
//CGRectMake(0, 0, 320, 480);
[self.view addSubview:AddSearchView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.8];
AddSearchView.frame = CGRectMake(10, 57, 310, 148);
//CGRectMake(0, 480, 320, 480);
[UIView commitAnimations];

You can use UIView's setAnimationDidStopSelector method to call another function once the current animation is complete. I have used this to link animations which heavy relied on timing. For that particular animation, I would try animating the UIView's frame property.
Also consider using CAKeyframeAnimation. http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CAKeyframeAnimation_class/Introduction/Introduction.html

Related

Animate two views like when you pass a phone call

I have made many tries to have the same effect of switch than the one you can see when calling a phone number : the front view disapear with a zoom effect, while the other one appears also with a zoom effect.
I can't achieve doing that effect, it's always a so-so. There seems to have a scale effect, with an action on opacity, but...
Do you know how this can be done to reflect that effect (not a so-so, I have tons of those) ?
// Make this interesting.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
self.view.alpha = 0.0;
self.view.frame = CGRectMake(self.view.center.x,self.view.center.y , 0, 0);
[UIView commitAnimations];
}
I hope this is a framework for a better animation. It's not guaranteed to work, but it's the best I could think of for the first part of the transition.
This will change the frame of your view controller's view so that it "sucks" itself into the center of the screen, which is a natural black color. Now that I think about it, a CGAffineTransform would have been much easier...
EDIT (For pedantry's sake): Starting with iOS 4, you can now use the newer, and much more syntactically clean, animation blocks and a nice transform:
[UIView animateWithDuration:0.25 delay:0.0 options:0 animations:^{
//animate the toolbars in from the top and bottom
[myTopView setFrame:CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44)];
[myBottomView setFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
//fade to black...
self.view.alpha = 0.0;
//and suck inwards.
self.view.frame = CGRectMake(self.view.center.x,self.view.center.y , 0, 0);
}
completion:^{
//do something to end nicely, or start another animation block.
}];

Cocoa touch - UIAnimation question

Hey guys, I still haven't found an answer to this so I think I'll ask you.
[viewOggetto setFrame:aFrame];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:viewOggetto.view];
[UIView commitAnimations];
this is a simple animation for a view to appear in a position and then go full screen.
My question is: how can I make the content of the view follow the animation as well?
Now I have the view frame animating correctly but everything that is inside the view just appears fullscreen instantly.
Thanks.
It's not entirely clear what you want to happen instead of it appearing full-screen instantly. You mean you want it to fade in? Set the alpha property on the subview to 0 and add it to self.view before you start the animation. Then set the alpha property to 1 within the animation.
but what viewOggetto exactly is? if it's a UIView then why to call viewOggetto.view?
is it a UIViewController?
You call both :
[viewOggetto setFrame:aFrame];
[viewOggetto.view setFrame:aFrame];
assuming it's a UIViewController, try this / prova cosi':
[self.view addSubview:viewOggetto.view]; // you need to have it before to animate it
// initial state of the animation:
[viewOggetto.view setFrame:CGRectMake(160, 240, 1, 1)]; // zoom from center
// viewOggetto.view.alpha = 0; // eventually to add a fadeIn animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
// ending state of animation:
// viewOggetto.view.alpha = 1; // restore to 1 to eventually to add a fadeIn animation
[viewOggetto.view setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
if it's a UIView just delete ".view" in every "viewOggetto.view" code
ciao,
luca
Just want to add to Jim's answer. UIView animations animate UIViews from one context to another. If the context doesn't exist before the [UIView beginAnimations:nil context:NULL]; then underside effects will happen. The context wont exist if the view hasn't been added to subview.

Make a bar slide onto iPhone screen

I'm making an iPhone web page and in order to optimise it for the device have decided to hide the menu bar and replace it with one button at the top. When this button is click a menu bar drops down and allows the user to go to another page. I'm having a bit of trouble trying to get the bar to slide down and up. Any help is much appreciated.
You need to use to animate the view. For example if menu is the variable which holds an istance of your bar (320x50px) you can animate up and down from the top with this code:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
if (menu.frame.origin.y == 0)
menu.frame = CGRectMake(0, -50, 320, 50);
else
menu.frame = CGRectMake(0, 0, 320, 50);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

Adding a animated view

I have a tableview and a normal view (let's say view 2) inside a normal view. All made in Interface builder. View 2 is above the tableview and needs to appear animated from above at the loading of the view. When pressing a button, the view disappears again. How can i do this?
thanks
You will have to animate this in a custom animation block. It should be fairly simple..
Set your view's frame so that it is above the screen and not visible:
[yourView setFrame:CGRectMake(0, -480, 320, 480)];
In the animation block just change your view's frame in the animation block:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:GROW_AND_MOVE_ANIMATION_DURATION_SECONDS];
[yourView setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
To dismiss it/ make it disappear use same animation with the previous frame:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:GROW_AND_MOVE_ANIMATION_DURATION_SECONDS];
[yourView setFrame:CGRectMake(0, -480, 320, 480)];
[UIView commitAnimations];
But before that consider whether you must bring it in from top, cause if bringing it in from bottom as a modal view meets your requirements, you can very easily use UIViewController's method:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
Good Luck.

Open view with slide effect from bottom to top on iPhone

I'm making an application for iPhone (which runs in landscape mode) (OS 3.0), and I want that when I touch a toolbar button it opens a view with a slide effect (similar to the effect when you touch 'Bookmarks' in Mobile Safari's toolbar) from the bottom to the top of the screen. The view is in the same XIB file as the button.
How can I do this?
Thanks in advance.
If you are asking about doing the animation custom here's a snippet that might help.
Lets assume the view "myView" is already added as a subview to the current view.
[myView setFrame:CGRectMake(0, 480, 320, 480)];
[myView setBounds:CGRectMake(0, 0, 320, 480)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[myView setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
The important numbers in there are the y positions in the setFrame rect (480 then 0), this moves it from offscreen to onscreen.
[self.tabBarController presentModalViewController:yourSlideController animated:YES];