【问题标题】:Presenting a view controller of custom size with navigation使用导航呈现自定义大小的视图控制器
【发布时间】:2013-04-04 04:39:33
【问题描述】:

我想展示一个自定义大小的视图控制器,比如 (500,500)。我尝试使用下面的代码来做到这一点,如果我单独呈现视图控制器,它可以在半透明的浅灰色背景下正常工作,但是当我将视图控制器放在导航控制器中时(我想做)有黑色背景出现了,我不想要这个,我想要灰色的。

我在这个问题的帮助下做了以下代码:

iOS -- how do you control the size of a modal view controller?

MyViewController *vc=[[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];

UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];

nav.modalPresentationStyle=UIModalPresentationPageSheet;

[self.window.rootViewController presentModalViewController:nav animated:YES];

CGRect r = CGRectMake(self.window.rootViewController.view.bounds.size.width/2 - 250,
                              self.window.rootViewController.view.bounds.size.height/2 - 250,
                              500, 500);
r = [self.window.rootViewController.view convertRect:r toView:vc.view.superview.superview];
  vc.view.superview.superview.frame = r;

任何猜测,我在这里错过了什么?或者有没有一种简单的方法来展示一个带有导航的自定义大小的 VC?

带导航:

没有导航:(我使用的是深色背景,所以它可能看起来像黑色但实际上不是)

【问题讨论】:

  • vc.view.superview.superview.frame=r 是干什么用的?
  • 减少VC相对于其父视图的框架。

标签: ios ipad uinavigationcontroller presentmodalviewcontroller


【解决方案1】:

【讨论】:

  • 是的,我明白了,但问题是,如果我呈现一个 ViewController 对象,默认情况下我会得到一个透明视图,而当我呈现一个带有 ViewController 的 NavigaitonContoller 时,我会得到一个黑色的视图。为什么会这样??
  • 可以放截图吗
  • 请尝试这样[self.navigationControler presentModalViewController:nav animated:YES]; 而不是[self.window.rootViewController presentModalViewController:nav animated:YES];
  • 我正在做这一切,所以这个控制器可以通过一个手势出现在任何屏幕上。所以我不能使用 self.navigationController 可能我会尝试 self.window.rootViewController.navigationController。
  • 哪个背景色??窗口还是 VC?
猜你喜欢
  • 1970-01-01
  • 2021-01-03
  • 2014-05-11
  • 2014-10-09
  • 1970-01-01
  • 2021-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多