iOS:presentModalViewController 框架
我有一个带有导航栏的导航控制器和以下代码。
panel = [[Panel alloc] initWithNibName:@"Panel" bundle:nil];
[self presentModalViewController:panel animated:NO];
panel.view.superview.frame = CGRectMake(250, 180, 550, 400);
我希望这个子视图位于导航栏上,虽然效果很好,但我也希望它有一个特定的框架;我不希望我的子视图全屏。我考虑过使用presentModalViewController,但是还有其他方法来覆盖导航栏吗?
I have a navigation controller with a navigation bar and the following code.
panel = [[Panel alloc] initWithNibName:@"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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
添加到导航栏的任何内容实际上都是一个视图。你有一些选择。我认为您不希望导航栏上有整个视图,因为它太大了,所以我假设您想通过按导航栏上的按钮来显示视图。
为此,只需向导航栏添加一个按钮,这里有几个选项或可以添加它们的位置。我通常使用 self.navigationItem.rightBarButtonItem 或 self.navigationItem .leftBarButtonItem,但您也可以尝试并在标题视图上获取它。我过去在导航栏的 titleView 中设置了一个按字母顺序分段的控件。
添加按钮后,您所要做的就是创建将连接到该按钮的操作,该操作会将标志(BOOL 实例变量)与 true 或 false 进行比较。如果为 true,则只需将 pannel.view 添加到 self.view,如果为 false,则只需
[pannel.view removeFromSuperview]
。添加和删除视图后不要忘记设置标志。
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 theself.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.
我不完全确定你想在这里完成什么,但我怀疑你当前的代码是正确的解决方案。在 iPhone 上,UIViewController 的视图预计会填充其窗口,因此您不应该尝试调整视图控制器的视图框架大小或获取模态呈现的 UIViewController 视图来填充小于全屏的内容。您能否更具体地说明您当前的控制器和视图结构是什么样的以及您希望构建什么效果?
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?