UIModalPresentationFormSheet size display

I am interested to know how I can resize a presentation when using the UIModalPresentationFormSheet modalPresentationStyle , it seems to have a fixed size, so I was wondering if any of them managed to control the pop-up presentation from the sizing.

So there is either a UIModalPresentationFormSheet with a fixed presentation size or full presentations, and I am behind something in between.

+43
ipad modal-dialog presentation
Nov 24 '10 at 12:08
source share
6 answers
 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); 
+71
Jan 31 '11 at 12:18
source share

You can customize the frame of the modal view after its presentation:

Tested in iOS 5.1 - 6.1 using 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 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. 

Update . The preferred presentation method of a presentation of a presentation of a presentation of iOS 6.0 also works correctly:

 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion 
+4
Nov 24 '10 at 20:51
source share

In ios8 and earlier works:

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

In 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) 

In iOS 8, you can also use the UIPresentationController, which gives you more settings.

+4
Sep 22 '14 at 7:47
source share

For iOS 8, simply implement the preferredContentSize delegate method (CGSize) on each view controller. He must solve all the problems with the size.

+3
Sep 25 '14 at 23:56
source share

Just for Fatos solution (excellent) If you create a view controller using the .xib file after selecting initWithNibName, you can save the view frame:

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

And then use it for superiew.bounds, so the view size in .xib will be used, and you can resize more visually.

+2
Oct 18 '11 at 17:30
source share

I put this code in the sheet view view controller:

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

Please note that resizing happens early enough for the presentation animation to look right.

-one
Jul 22 2018-12-22T00:
source share



All Articles