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
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];
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).
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];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With