Make a bar slide onto iPhone screen - iphone

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];

Related

Transition of Modal View in ios

Modal view in iOS appears from bottom of the screen to top, and dismisses from top to bottom of the screen. I would like to know, is there any way i can revert the above and make the model view appear from top of the screen to bottom of it. Thus when it is dismissed it will animate from bottom to top.
Yes why not I think I can offer you a workaround :) ....
First Make a custom UIView and set its coordinates as
View.frame=CGRectMake(0, 0, 320, 0);
Then use Animations to move it from top to bottom and vice-versa like this:-
For making it appear use the following code:-
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.25];
View.frame = CGRectMake(0, 0, 320, 460);
[UIView commitAnimations];
For dismissing it use :-
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.25];
View.frame = CGRectMake(0, 0, 320, 0);
[UIView commitAnimations];

Animating a View Like This Example

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

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.

how to open a new uiview like a popup?

i have a tabbar app. there is a button in one of tab.
i want to open a new uiviewcontroller by animation like popup when i press the button.
popupviewcontroller has a uiwebview. i want to show some web pages in popup view.
i designed the popupview in IB.
how can i open my popupviewcontroller with animation like FBConnect.
FBconnect opens the login dialog view with animation like a popup.
You won't be able to open like a popup a UIViewController.
For that you will have to use a simple UIView
Add the UIview (popup shape like) to your current view.
- (void) initPopUpView {
popup.alpha = 0;
popup.frame = CGRectMake (160, 240, 0, 0);
[self.view addSubview:popup];
}
- (void) animatePopUpShow {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationWillStartSelector:#selector(initPopUpView)];
popup.alpha = 1;
popup.frame = CGRectMake (20, 40, 300, 400);
[UIView commitAnimations];
}
Yup you can open look like popup window u just use this code and run it..
its open very slowly depends on your time given...
Might be helpful
(void)popup
{
UIView *AView1=[[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2,self.view.frame.size.height/2, 0, 0)];
[AView1 setBackgroundColor:[UIColor redColor]];
[UIView animateWithDuration:2.5 animations:^{AView1.frame = CGRectMake(35, 10, self.view.frame.size.width-70, self.view.frame.size.height-100);}];
}

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];