I am interested to know on how I can resize the view when using UIModalPresentationFormSheet
of modalPresentationStyle
, it looks like it has a fixed size so I was wondering if anyone out there did managed to manipulate the popup view from the sizing perspective.
So there is either UIModalPresentationFormSheet
with a fixed view size or full views and I am after something in between.
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);
You are able to adjust the frame of a modal view after presenting it:
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'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.
Update The preferred iOS 6.0 view controller presentation method also works correctly:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
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 UIPresentationController which gives you more customization options.
For iOS 8, simply implement the delegate method (CGSize)preferredContentSize on each view controller. It should resolve all the size issue.
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