如何设置 Modalview 控制器的中心。我能找到任何解决方案吗?

Posted

技术标签:

【中文标题】如何设置 Modalview 控制器的中心。我能找到任何解决方案吗?【英文标题】:How to set the center of Modalview controller.Is there any solution I can find? 【发布时间】:2013-08-06 11:44:59 【问题描述】:
How to set center of the modalview controller to its center of self.view or Appdelegate window.I have sample code.The following code is presenting modalview at the right corner of the screen not at the center of the screen.
   MaterialDetailsViewController *materialDetails =[[MaterialDetailsViewController alloc]initWithNibName:NSLocalizedString(@"MaterialDetailsViewController",nil) bundle:nil];
      materialDetails.view.frame = CGRectMake(0, 0, 750, 650);
      materialDetails.modalPresentationStyle = UIModalPresentationFormSheet;
      materialDetails.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;  //transition shouldn't matter
      [self presentViewController:materialDetails animated:YES completion:nil];
     materialDetails.view.superview.frame = CGRectMake(self.view.superview.center.x - (750/2),
                                                       self.view.superview.center.y - (650/2),
                                                        750,650);
I tried to set the modalview frame center to self.view.center in MaterialDetailsViewController class like below
AppDelegate *delegate = [AppDelegate sharedInstance];
self.view.center = delegate.window.center;

但它不适合屏幕的中心。我可以用 Popovercontroller 试试这个我可以做到最好,但我无法用 modalview 控制器管理。我认为这篇文章对那些努力为modalview设置框架。

【问题讨论】:

【参考方案1】:

添加到您的 MaterialDetailsViewController

- (void)viewWillLayoutSubviews 
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 750, 650);

ios 5+

【讨论】:

以上是关于如何设置 Modalview 控制器的中心。我能找到任何解决方案吗?的主要内容,如果未能解决你的问题,请参考以下文章

如何将 modalView 设置为 false?

sonar 6的序列号`~``我能找出来很多。不过输入哪个啊。 。。它一共有三个空格`可咱一个也没看懂的`

modalview 关闭后 TableView 未重新加载

iOS - 如果应用程序首次启动 - 呈现 ModalView

Dismiss ModalView 在这里不起作用

从 MasterViewController 呈现的 ModalView 在 iOS 5.1 中不再是全屏