通过导航呈现自定义尺寸的视图控制器

时间:2013-04-04 04:39:34

标签: ios ipad uinavigationcontroller presentmodalviewcontroller

我想呈现自定义大小的视图控制器(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与导航?

导航:

enter image description here

没有导航:(我使用深色背景,所以它可能看起来像黑色但不是 enter image description here

相关问题