开发者

addSubview like modal

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,开发者_C百科 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜