使用位于iPad应用程序中心的导航控制器打开模态视图

时间:2011-12-19 18:50:56

标签: iphone uinavigationcontroller presentmodalviewcontroller

我正在尝试在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

如何在窗口中央以较小的尺寸打开此窗口。

由于

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:3)

以下是支持最新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);

希望这会对你有所帮助。

答案 2 :(得分:0)

您可以执行以下操作:以模态方式呈现视图控制器后,将其大小设置为所需大小,然后将其居中。

...

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;