I have a UIViewCOntroller, and in that i have a button and a text field. When i click the button i display a UIToolBar.
Now when i click anything in the background (the textfield or the blank view) i need this UIToolBar to disappear. How can i do this programmatically ?
I know how to add a UIToolBar but all what i need to know is to hide it when the user clicks on the background.
I don't think i will have to paste any code here or show my workings so far, coz i have no clue how to get this done
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setToolbarHidden:YES animated:YES];
}
May be it can help you....
You will need to capture a touch on the views outside of your toolbar to achieve this. If you have a custom UIView base class that all of your other views use, you might start there. Otherwise, perhaps use some sort of toggle to show/hide your toolbar instead in your UIViewController.
The easiest way to do this is to make a single large clear button that is behind the first button but above everything else. Normally have it set to hidden but when you show the toolbar unhide the button as well. When the button is clicked have it hide the toolbar and its self. No need to do anything crazy like sub classes.
Related
I am trying to make some kind of popup view when a button i pressed on the iPhone. And it would be nice if I could manage that popup view with a ViewController. I have found out that the UIPopoverController could have been the solution, but it seems that it only works on the iPad...
But anyway, are there any similar solutions for the iPhone?
I am using storyboard
Check out these repos on Github:
https://github.com/werner77/WEPopover
https://github.com/50pixels/FPPopover
Create a separate view controller and resize its xib file and make it look like a popup.
Then ADD this view controller as a subview, and also add it as childController too.
[self addChildViewController:self.popOverViewController];
[self.view addSubview:self.popOverViewController.view];
Now Make it hidden initially.
self.popOverViewController.view.hidden = YES;
If a user taps on Button then using fade in & Fade out animation you can hide/unhide it.
I can tell you how to fade in and fade out if you want to know it further, I hope you can do it easily.
In interface builder make a UIView size of the screen and then make another in that Uiview with the style, size and the such for your pop over. Make its class, hook everything together.
CustomPopUpView *view = [[CustomPopUpView alloc] initWithFrame.....]
Add this all to your UIViewController with
[self.view addsubview:view]
Then attach a tapGestureRecognizer to the back view that animates the whole view off screen when tapped. So now if they click off your pop over view it close it will animates it off screen.
Hope this makes sense.
BooRanger
How can I make a custom view in iOS which appears above the existing view,but smaller? It should be like UIAlertView, but taken from a .xib file. After user taps a certain button, the small view vanishes and the normal view appears.
If this is posiible, how can I do it? And.. if it's not hard for you, please, include code.
Thanks in advance!
I think what you're looking for is a modal view. Modal views make it easy to have a view take over the screen for a little while, then when they get dismissed have the background view resume where it left off without having to worry about who's on top or handling events in partially-obscured views.
Here is Apple's article describing it.
They key is to have the controller class for your view call [self presentModalViewController:popupController animated:YES]; where "popupController" is the view controller for the view you want to show up. When you're ready to make it go away, call [self dismissModalViewControllerAnimated: YES];
You can just use the addSubview: method on your UIWindow or your visible UIViewController's view to show the UIView, and you can hide/remove it later by calling removeFromSuperview on the presented UIView.
Plenty of applications seem to do this. For example, go to Apple's mail application and press the "reply" button on the toolbar. You'll get a menu with buttons that say "Reply", "Reply All", "Forward" and "Cancel" that will scroll up from the bottom.
The way I figure I could do this is to create a short view in IB with the buttons I want, present it modally, and right a view controller to handle the buttons.
It seems like this is so common that there must be an easier way to do it (like how easy it is to add to the toolbar and navigation bar).
Is there some widget or shortcut that I am missing?
This is actually just a UIActionSheet. You can create one pretty easily.
http://ykyuen.wordpress.com/2010/04/14/iphone-uiactionsheet-example/
Just make a view controller with the controls you want in IB and then call [self presentModalViewController:[[[MyModalViewController alloc] init] autorelease] animated:YES] on the current view controller.
I would like to add a uitoolbar able to slide -in from the top of the screen when some button is pushed. With all the research done this week-end I am still stuck. Please help.
If you are using a UIToolbar within a UINavigationController you may simply call:
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated
Otherwise you'll have to setup a custom animation.
I have a standard UITableView with a UINavigation bar at the top with the standard back button, etc.
I have a button that pops up a "modal dialog" box, which is a view that sits on top of and almost obscures (but doesn't quite) the view underneath. Problem is, the buttons (including the "back" nav button) are still visible and thus touchable.
I've tried setUserInteractionEnabled:NO on the view of the UITableViewController, but that doesn't seem to work-- at least the navigation items are still touchable. But the navigationItem isn't a view subclass.
Any other ideas? Missing something obvious?
Thanks.
Ended up with the same problem in a similar situation:
iPhone: how do I set up a clear window-size "blocker view"?
Solved it using a transparent view that swallows events, sitting across the whole window. Feels kludgey but works.
Try something like this:
[[[tableViewController navigationItem] leftBarButton] setEnabled:NO];
I ran into similar issue and used following to hide the nav bar:
[self.navigationController setNavigationBarHidden: YES animated:YES];