【问题标题】:Open Modal View with navigation controller in the centre of iPad application在 iPad 应用程序中心使用导航控制器打开模态视图
【发布时间】:2011-12-19 18:50:56
【问题描述】:

我正在尝试在我的 iPad 应用程序的中心打开一个模态视图控制器。

这就是我在代码中所做的事情

Settings_iPad *vController = [[Settings_iPad alloc]
                                            initWithNibName:@"Settings_iPad" bundle:nil];

    vController.modalPresentationStyle = UIModalPresentationFormSheet;

    // Create a Navigation controller
    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:vController];

    // show the navigation controller modally
    [self presentModalViewController:navController animated:YES];

    // Clean up resources
    [navController release];
    [vController release];

这就是我得到的http://www.use.com/48bcd41a28a13b562140

如何在窗口中心以较小的尺寸很好地打开此窗口。

谢谢

【问题讨论】:

    标签: iphone uinavigationcontroller presentmodalviewcontroller


    【解决方案1】:

    将导航控制器上的modalPresentationStyle 设置为UIModalPresentationFormSheet 并以模态方式呈现。

    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:navigationController animated:YES];
    

    【讨论】:

    • 谢谢UIModalPresentationFormSheet 正是我想要的!
    【解决方案2】:

    这是支持最新 iOS 7 的解决方案!

    navController.modalPresentationStyle = UIModalPresentationStylePageSheet; // can be form sheet also
    navController.modalTransitionStyle = UIModalTransitionStyleCrossDisolve;// in IOS 7 no other style let you resize your view controller's frame.
    /* important step*/
    self presentViewController:navController animated:YES completion:^{//any code you want};];// from iOS 6 onward this is supported
    // now set size of the viewcontroller, if you will set before presenting it will simply ignore.
    navController.view.superView.frame = CGRectMake(x,y,width,height);
    navController.view.superView.center = CGPointMake (x, y);
    

    希望这会对你有所帮助。

    【讨论】:

      【解决方案3】:

      您可以这样做:在模态显示视图控制器后,将其大小设置为您想要的大小,然后将其居中。

      ....

      navController.modalPresentationStyle = UIModalPresentationFormSheet;
      [self presentModalViewController:navController animated:YES];
      //these two lines are if you want to make your view smaller than the standard modal view controller size
      navController.view.superview.frame = CGRectMake(0, 0, 200, 200);
      navController.view.superview.center = self.view.center;
      

      【讨论】:

      • 是的。我在这样的一个项目中使用了它。
      猜你喜欢
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多