views:

224

answers:

2

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.

A: 

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.

Daniel Bauke
Can you give a pseudo example of how that might be done?
I can create a new UINavigationController and init it with the parent UIViewController but then I can't give the parent navigation bar to the modal since it is read only. Even if I try something like this newNavigationController.navigationItem.title = @"test", it is ignored. The modal navbar is blank.
Well, I rather do it in `-(void)viewDidLoad` method of created `UIViewController` (and actually I did it once :-)
Daniel Bauke
Yep - title assignment works in the modal's viewDidLoad. But does that mean I basically have to recreate the navigation bar from scratch that exist in the parent, since that is the navigation I want to persist?
You can try to pass it as an additional `@property`.Meanwhile I thought about having the same navigation in regular controller and its modal and I felt it might be a bit vague for a user -- don't you think so?
Daniel Bauke
+1  A: 

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