How to create a UINavigationController that hovers onscreen (not translate the screen downward) - ios

I would like to have a UINavigationController that hovers on the current screen instead of "translating" the screen downward to make way for it.
Currently my implementation goes like this:
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonSystemItemCancel target:self action:#selector(backButtonTapped)];
[self.navigationItem setBackBarButtonItem:backButton];
So that what happens is everytime I show the navigationItem, it slides itself downwards into the screen, translating the entire screen. And then when I hide it, it slides out, pulling back the entire screen up. I'd like it to hover instead, i.e. the position of the screen remains untouched. Thanks!

As per question, you want to animate screen when we push screen from navigation controller. I have done in my project. Steps as below
1) When you push view controller from Navigation Controller means, You have to animate current view controller when we push. code as below
(void)viewWillDisappear:(BOOL)animated {
[UIView beginAnimations:#"animation2" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.7];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[super viewWillDisappear:animated];
}
2) If you want to pop from second view controller to first view controller means, you have type same code in second view controller.. You can change animation transition side by modify this method argument setAnimationTransition

Related

Popup the uiview in button click in iOS

I have one mainview UIViewController. in that view put one UIView name loginview with small size(self.loginview.frame = CGRectMake(4,166,306,153);
In mainview uiviewcontroller i put one button if i click that button loginview want to display like popup... how can i achieve this help me here code.
- (IBAction)Regbtn_click:(id)sender
{
//in this place i want to write the code for login view want come like popup.. help me..
loginview.hidden=false
}
Instead of setting hidden property of your loginview, set its alpha to 0.0 and you can use this animation
-(IBAction)Regbtn_click:(id)sender {
//[self.view addSubview:self.loginView]; if your loginview is not added to view, if it is, ignore this line
[UIView animateWithDuration:0.5 animations:^{
self.loginView.alpha = 1.0; //to display loginview
} completion:^(BOOL finished) {
}];
}
You can animate the view with two animations:
1) scaling
2) fading
View Controller
->Button (Viewcontroller Child)
->LoginWrapperView (Viewcontroller Child)
->black-transparent View (LoginWrapperView Child)
->login View (LoginWrapperView Child)
Add black semi-transparent view (with opacity of 0.2 i think) on screen and above that place your loginView and set its opacity to 0.
[LoginWrapperView SetHidden:YES];
[loginView SetAlpha:0];
[loginView SetFrame:CGRectMake(0,0,0,0)];
Now when you click on the button,
[LoginWrapperView SetHidden:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
//position on screen
[loginView SetAlpha:1];
[loginView SetFrame:<your CGRect goes here>];
[UIView setAnimationDidStopSelector:#selector(finishAnimation:finished:context:)];
//animate off screen
[UIView commitAnimations];
Then handle Tap Getsture on semi-transparent view to close or hide the same by reversing the same animation with different values.
You can push your view modally or use a nice library like MZFormSheetController that do just that.
Here's how it looks like
It is simple just present your view. You could also make the background transparent and many other customization.
YourPopupViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PopupView"];
-(IBAction)buttonClick{
// present form sheet with view controller
[self mz_presentFormSheetController:vc animated:YES completionHandler:^(MZFormSheetController *formSheetController) {
//do your login stuff
}];
}

How to flip a view with a label on the front side and another label on the back side - see image

How can I flip a view with a label on the front side and another label on the back side when a button is clicked? Something that looks like the image below.
What would be the logic to create this effect?
Thanks
EDIT:
Sorry about the confusion but please note that I'm just talking about a view not ViewControllers, this effect will happen within the same viewController. I have updated the image to reflect that the view I'm talking about is a subView inside the main view.
I too had something very similar situation, on click of a button on ViewController1 I have to move to another ViewController2. I used this code,
//code this in ViewController1
-(IBAction)flipView:(id)sender
{
ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[[self navigationController] pushViewController:view2 animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[view2 release];
}
//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[[self navigationController] popViewControllerAnimated:YES];
[UIView commitAnimations];
}
But in this code I am using 2 classes, if it is fine to you, use this code. Hopes it solves your problem to some extent.
What you can do is use two UIViews, one for the first side, one for the second side.
Show the first view, hide the second view, and set the second view's frame to have a width of 0.
Then, when your first view is visible, animate its frame to have a width equal to 0. Hide the first view, unhide the second view, and animate the second view's frame to the desired frame.
Edit : This does not appear to work well if you have labels in your views, as this is a 2D flip. Sorry about that. #Maverick's answer could work pretty well in your case.
Call this method in your viewController, your viewController view flips and viewController life cycle method calls and simply change the image of UIImageView you want to display in
-(void)viewdidload method.
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Please vote up if you find it helping

Methods gets called when app goes to the background

my app consists of a table view controller and a view controller. when i press a cell in the table view, the toolbar at that view slips with animation down outside the screen and when i'm in the view controller and press back, the toolbar bar slips upwards to it's original position. My problem is, i figured out a bug that when i'm in the view controller and press the home button to exit the app and then come back. the app resumes where i left but when i go back to the table view, the toolbar shifts upwards beyond it's original position. the sliding of the toolbar works fine when i'm in the app before exiting. so there's like something is being called to reset the toolbar to it's origin and thus adding the additional y-axis point to shift more upwards. does anybody know what are those methods?
Code:
i have this in the viewWillAppear method of the view controller:
[UIView animateWithDuration:0.7 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
self.navigationController.toolbar.hidden = YES;
}];
and in the same view when it needs to disappear i added this in the viewWillDisappear:
[[self.navigationController toolbar] setHidden:NO];
[UIView animateWithDuration:1 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y - self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
}];
i tried this as another way to animate the hiding of the toolbar but there is no animation:
- (void) viewWillAppear:(BOOL)animated
{
[self.picker setHidden:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
}
- (void) viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
[self.course setValue:self.nameTextField.text forKey:#"courseName"];
[self.course setValue:[NSNumber numberWithInt:[self.creditsTextfield.text integerValue]] forKey:#"courseCredits"];
[self.course setValue:[NSNumber numberWithInt:[self.chaptersTextfield.text integerValue]] forKey:#"courseChapters"];
[self.course setValue:self.gradeTextfield.text forKey:#"courseGrade"];
}
For one thing, you should use frame instead of center, but replace the viewWillDisappear animation line with this:
self.navigationController.toolbar.frame = CGRectMake(0,0,self.navigationController.toolbar.frame.size.width, self.navigationController.toolbar.frame.size.height);
and tell me what happens...
That should fix your problem.
Since you are using the toolbar belonging to a UINavigationController (and not a standalone UIToolbar instantiated and added to a UIView by your own controller), it's better to use the methods that UINavigationController exposes, because you don't know how it manages and move its UIToolbar.
Try to put just this in viewWillAppear:, instead of the entire animation block
[self.navigationController setToolbarHidden:NO animated:YES];
and this in viewWillDisappear:
[self.navigationController setToolbarHidden:YES animated:YES];
i fixed it! i aded the following lines of code in viewWillDisappear:
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, 458);
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
since the problem seems that when the app goes background then foreground the toolbar resets to it's original position and thus after navigating back to the table view the toolbar is shifted beyond it's original position. therefore the first line i added resets the toolbar to it's original position while still hidden then shift it down. after that the block of animation is done. i did this so that the animation works on the following cases:
1. the user enters the detail view from the table view then goes back to the tableview without exiting the app.
2. the user enters the detail view from the tableview then exits the app and then resume the app and goes back to the table view.

Empty table rows becomes transparent right before page curl transition

I have a table view. When you add a new item to the table, I display a form sheet for you to enter the name and description of the item to be added to the table. When you press Done, the modal view dismisses and the item's detail view is pushed. Instead of pushing the detail view like you normally would with a navigation controller, I use a page curl transition.
DetailViewcontroller *detailViewcontroller = [[DetailViewcontroller alloc] initWithStyle:UITableViewStyleGrouped];
detailViewcontroller.coolObject = collectionOne;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.00];
[UIView setAnimationDelay:.25];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
//Start Animation
[UIView commitAnimations];
[self.navigationController pushViewController:detailViewcontroller animated:NO];
[detailViewcontroller release];
This works perfectly when there's enough populated rows to fill the screen. However, if there's only a few rows populated, the rest of the table becomes transparent where there's no rows right before the page curl transition and you can see parts of the detail view underneath right before the page curl transition loads.
It looks like the detail view is displayed first, then an empty shell of a view curls away after the fact.
I have set the table rows and table background color to black, white, anything but clearColor, and it still does it.
Is it a timing issue? Should I put timing in to make sure that the detail view isn't pushed until after the modal view is dismissed? Maybe tell the Add item controller to display the detail view and not the tableview's addViewDisDimiss delegate method?

View drawn under status bar

So i managed to load another view when someone presses a button ,but it loads it to high. `i don't know why this happens. The difference is exactly the top bar hight. This is my code:
In the delegate i have:
- (void)flipToAbout {
AboutViewController *aaboutView = [[AboutViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[self setAboutController:aaboutView];
[aaboutView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[homeController.view removeFromSuperview];
[self.window addSubview:[aboutController view]];
[UIView commitAnimations];}
In the about view i didn't change anything.Please tell me what is the problemm .Thanks.
The problem is that you're adding your view directly to the window without accounting for the navigation bar. Normally, if you have a navigation bar, you use a navigation controller to manage your view controllers. Pushing a view controller onto the nav controller's stack causes the nav controller to add that view controller's view to the window for you, and you don't have to worry about the nav bar. Since you're doing it by hand, though, you'll want to reposition the view after you add it to the window.
Note that this problem doesn't have anything to do with nibs except that you load your view from a nib. The same thing would happen if you created the view programmatically.

Resources