I have a navigation view controller and I want a subview to slide on top of it when a button in the parent view is clicked. Now, the thing is when I do this:
[parentView addSubview:slideView];
[UIView beginAnimations]
//setting the frame for sliding
[UIView CommitAnimations]
the sliding view goes under the navigation bar after sliding. I would like it to slide on top of the navigation bar of the parent view. How do I achieve this?
Essentially, all I am trying to do is: replicate the iPhone Add Contact application with the only difference being; unlike me, they don't have a navigation controller on the parentView but just a navigation bar with a system add button.
Anyone!!
Hows about using a Modal View Controller....
UsernamePasswordViewController *usernamePasswordView = [[UsernamePasswordViewController alloc] initWithNibName:#"UsernamePassword" bundle:[NSBundle mainBundle]];
[self.navigationController presentModalViewController:usernamePasswordView animated:YES];
[usernamePasswordView release];
This will slide upwards by default over anything
How about something like:
[parentView addSubview:slideView];
[parentView bringSubviewToFront:slideView];
// etc
Related
I have a uitableview inside and uiview which is being presented in a navigation view (so it has a navigation menu). Under the navigation menu I have a uitoolbar appearing when the view loads and disappearing when the load is poped from the navigation stack.
The issue I am having with this is that when I animate this view onto the stack with normal animation transition right to left, the tableview dose not do this it just appears quickly before the view is finishe sliding into view. Then when you select the back button and the view begins to animate from left to right it dissipears before the end of the animation again.
I would like to know how to get this toolbar to animate with the rest of the view, right to left, left to right etc instead off appearing over the sliding effect abnormally.
This is how I call and dissmiss the toolbar at the moment.
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:NO];
[self.navigationController.toolbar setFrame:CGRectMake(0, 60, 320, 30)];
self.navigationController.toolbar.tintColor = [UIColor darkGrayColor];
[SeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height)];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:YES animated:NO];
[super viewWillDisappear:animated];
}
which is pretty much the standard way of doing things.
Any help would be greatly appreciated.
The toolbar property of the navigation controller is already onscreen, but is hidden from view. If you want a toolbar to animate on and off with a certain view, add the toolbar to that view. Then the toolbar will animate on and off as part of the view.
I have a viewController and I am trying to add a subview to it such that it will cover the whole screen, however this has a navigationController in it so that adding a subView always adds it below the navigation bar, is there a way to simulate a presentModalViewController in cases like this?
You can add the subview to the view controller and then hide the navigation controller from the top or you could still push it to the navigation controller and then just remove the navigation controller from the top again and then you could use pop to go back and forth.
the code to push a view controller is
if(!self.YOURVIEWCONTROLLER){
self.YOURVIEWCONTROLLER = [[YOURVIEWCONTROLLER alloc] initWithNibName:#"YOURVIEWCONTROLLER" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.YOURVIEWCONTROLLER animatedLYES];
and on the next NEXTView.m add
[self.navigationController setNavigationBarHidden:YES];
remember to create an instance of YOURVIEWCONTROLLER in the .h file. Or you could do a simple
[self.view addSubview:NEWVIEW];
[self.navigationController setNavigationBarHidden:YES];
at least at bear minimum the line for making the navigationController hide is there.
I seem to recall once having a similar problem, and I seem to recall the solution was to add the subview to the navigation controller (as the view controller is already a sub view of the navigation controller) rather than adding it to the view controller.
I recently have similar problems and after spending 5 to 10 min I get the exact solution...
According to my solution I simply add my custom UIView to subview of navigationController.view
Like This :-
[self.navigationController.view addSubview:popOver];
popOver - Your custom UIView
Happy Codding :)
Add the view to the superview of the navigationController's view.
[navigationController.view.superview addSubview:viewController.view];
Perhaps you could hide the navigation bar when you add the subview. I have a method on my ViewController that looks like this:
self.navigationController.navigationBarHidden = YES;
UIView *v = [[UIView alloc] initWithFrame:self.view.frame];
v.backgroundColor = [UIColor redColor];
[self.view addSubview:v];
When that code executes, my navigation bar disappears and a full screen red view replaces it.
I trying to put a controller in the background on a Navigation controller, to move the last and show a menu...
ment = [self.storyboard instantiateViewControllerWithIdentifier: #"MenuEnt"];
[self.view addSubview: ment.view];
[self.view sendSubviewToBack:ment.view];
But when I move the controller only appears a black area... :(
In the iPhone maps app there's a toolbar at the bottom of the map view (it contains the Search/Directions segment control and others). When moving from the map view by clicking on a callout, the toolbar slides out with the map view, leaving the next view (a table controller) with no toolbar.
I've tried to do the same thing with [self.navigationController setToolbarHidden:YES animated:YES] in the second view controller, but this gives a strange toolbar sliding down animation, while the map view is sliding to the left.
Using [self.navigationController setToolbarHidden:YES] in viewDidLoad also causes a bad effect (it makes the toolbar disappear the moment the push animation starts, leaving an ugly white space).
I'm assuming the answer to this is to use a nib file, but I'd prefer to do it programatically (if possible).
How can I get the toolbar to "stick" to the map view and slide out with it when I push a new view controller? Thanks.
Gourmet Haus Staudt http://img.skitch.com/20100518-xfubyriig48d3ckaemjg2ay8q.jpg
It turns out the answer is to create the toolbar directly and add it to the view yourself. This is in the code for a UIViewController with a UINavigationController. The frame coordinates can change according to what is on screen.
- (void)viewDidLoad
{
// Add a toolbar to the view
CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"compass.png"]
style:UIBarButtonItemStyleBordered
target:self
action:#selector(zoomToCurrentLocation)];
compassButton.width = 30.0f; // make the button a square shape
[myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
[compassButton release];
[self.view addSubview:myToolbar];
[super viewDidLoad];
}
I was around this for a day once. Really dont get the programatically answer, but the best way to views to behave correctly, is to do the interface in the interface builder. If you set items for a toolbar in your code like:
[self.navigationController setToolbarItems: control1, control2,..., nil] animated: NO];
with my little experience, I can say that you are saying to the entire application to have a toolbar present when you push new views unless you hide it (or you are using a tabBar), but hiding it you get those unwanted effects.
You can try this:
[self.navigationController setToolbarHidden:YES animated:YES];
in your first controller - (void)viewWillDisappear:(BOOL)animated method,
and setting hidden to NO in - (void)viewWillAppear:(BOOL)animated method in the first controller too.
Hope this helps.
PS: And if you get the programatically answer, let me know! =P
Override the second view controller's -viewWillAppear: method to hide the toolbar.
How can I get a UIView to transition via addSubview like the presentModalViewController does? The available animations don't seem to do this.
I would use the modal but I have a navigation bar at the top and don't want to disable it. Also, the modal overlays on the navigation bar. If there is a way to have it so the modal doesn't disable the nav bar, I can go with that approach. But since it is a modal, I don't think that is possible.
Pushing a modal view controller with the same navigation state seems like it would break the stack metaphor modeled by the navigation controller, which is weird, but I'll assume you've thought that through.
If you want to just add a subview that animates in from the bottom of the screen, you can do it like this:
CGRect onScreenFrame = viewToAdd.frame;
CGRect offScreenFrame = onScreenFrame;
offScreenFrame.origin.y = self.view.bounds.size.height;
viewToAdd.frame = offScreenFrame;
[UIView beginAnimations:#"FakeModalTransition" context:nil];
[UIView setAnimationDuration:0.5f];
[self.view addSubview:viewToAdd];
viewToAdd.frame = onScreenFrame;
[UIView commitAnimations];
If you use presentModalViewController with a any UIViewController as an argument you will have #property(nonatomic, readonly, retain) UINavigationItem *navigationItem available there and you can copy or create the navigation bar with it.