开发者

iOS: presentModalViewController frame

I have a navigation controller with a navigation bar and the following code.

panel = [[Panel alloc] initWi开发者_C百科thNibName:@"Panel" bundle:nil];
[self presentModalViewController:panel animated:NO];
panel.view.superview.frame = CGRectMake(250, 180, 550, 400);

I want this subview to be on the navigation bar and although that works fine, I also want it to have a specific frame; I don't want my subview to be full-screen. I thought about using presentModalViewController, but is there any other way to drape the navigation bar?


Anything added to the navigation bar is actually a view. You have some options. I don't think you want the whole view on a navigation bar since it is too big, so I'm going to assume you want to display the view by pressing a button on the navigation bar.

For this simply add a button to the navigation bar, here you have several options or places you can add them in. I usually use either the self.navigationItem.rightBarButtonItem, or the self.navigationItem.leftBarButtonItem, but you can also play around and get it even on the title view. I have setup in the past an alphabetical segmented control in the titleView for the navigation bar.

Once you added the button, all you have to do is create the action that will be connected to that button that will compare a flag (BOOL instance variable) to true or false. If true, then simply addSubview the pannel.view to self.view, and if false just [pannel.view removeFromSuperview].

Don't forget to set the flag after add and remove the view.


I'm not totally sure what you are trying to accomplish here but I doubt that your current code is the right solution. On an iPhone UIViewController's views are expected to fill their window, you shouldn't be trying to resize a view controller's view's frame or get a modally presented UIViewController's view to fill less than the full screen. Can you be more specific about what your current controller and view structure looks like and what effect you are hoping to construct?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜