UIModalPresentationFormSheet调整视图

我有兴趣知道如何使用UIModalPresentationFormSheetmodalPresentationStyle调整视图大小,它看起来像一个固定的大小,所以我想知道如果有人在那里设法从大小的angular度来操纵popup视图。

所以有一个固定的视图大小或全视图的UIModalPresentationFormSheet ,我之间的东西之间。

 MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; targetController.modalPresentationStyle = UIModalPresentationFormSheet; targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:targetController animated:YES]; // it is important to do this after presentModalViewController:animated: targetController.view.superview.bounds = CGRectMake(0, 0, 200, 200); 

展示之后,您可以调整模态视图的框架:

testingiOS 5.1 – 6.1,使用XCode 4.62

 MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease]; targetController.modalPresentationStyle = UIModalPresentationFormSheet; targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter [self presentModalViewController:targetController animated:YES]; targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after presentModalViewController targetController.view.superview.center = GPointMake(roundf(self.view.center.x), roundf(self.view.center.y));//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc. 

更新首选的iOS 6.0视图控制器演示方法也可以正常工作:

 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion 

在ios8和更早的作品中:

 AboutViewController * _aboutViewController = [[AboutViewController alloc] init]; _aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet; if(IS_IOS8) { _aboutViewController.preferredContentSize = CGSizeMake(300, 300); } [self presentViewController:_aboutViewController animated:YES completion:nil]; 

在AboutViewController.m中

 - (void)viewWillLayoutSubviews{ [super viewWillLayoutSubviews]; if(!IS_IOS8) { self.view.superview.bounds = CGRectMake(0, 0, 300, 300); } } 

IS_IOS8

 #define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) 

在iOS 8中,你也可以使用UIPresentationController,它给你更多的自定义选项。

对于iOS 8,只需在每个视图控制器上实现委托方法(CGSize)preferredContentSize即可。 它应该解决所有的大小问题。

只是为了扩大Fatos的解决scheme(伟大的一个)如果你正在创build视图控制器使用一个.xib文件后的alloc initWithNibName你可以存储视图帧:

 CGRect myFrame = targetController.view.frame; ... targetController.view.superview.bounds = myFrame; 

然后将它用于superview.bounds,因此将使用.xib中视图的大小,并且可以更直观地更改大小。

我把这个代码放在表单视图控制器中:

 -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.view.superview.bounds = CGRectMake(0, 0, 540, 500); // your size here } 

请注意,resize足够早,演示animation看起来正确。