Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing UIModalPresentationFormSheet on iOS 8

I'm trying to resize an UIViewController presented as a modal on iPad using UIModalPresentationFormSheet, and although I got it working on <= iOS 7, I can't on iOS 8

like image 273
Alvaro Franco Avatar asked Jul 18 '14 16:07

Alvaro Franco


3 Answers

For iOS 8 you have to set "preferredContentSize" property, but for iOS 7 and older you have to set the superview.frame property.

Example code:

UIViewController* modalController = [[UIViewController alloc]init];
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
modalController.modalPresentationStyle =  UIModalPresentationFormSheet;

CGPoint frameSize = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.95f, [[UIScreen mainScreen] bounds].size.height*0.95f);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

// Resizing for iOS 8
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y); 
// Resizing for <= iOS 7
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);

UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[vc presentViewController:modalController animated:YES completion:nil];
like image 65
Micho Avatar answered Sep 23 '22 12:09

Micho


this depends on if you're using UIPopoverPresentationController or UIPresentationController. You can try setting the "preferredContentSize" property to be your new content size (the "contentSizeForViewInPopover" property is deprecated in iOS 8).

like image 9
kevinl Avatar answered Sep 19 '22 12:09

kevinl


To resize a UIViewController's view, when it is already presented with UIModalPresentationFormSheet modal presentation style and is visible, use for iOS 8+:

self.preferredContentSize = CGSizeMake(width, height);

[UIView animateWithDuration:0.25 animations:^{
    [self.presentationController.containerView setNeedsLayout];
    [self.presentationController.containerView layoutIfNeeded];
}];
like image 8
bteapot Avatar answered Sep 19 '22 12:09

bteapot