I present a small "login" UIViewController
as a UIModalPresentationFormSheet
with custom bounds. In the viewWillLayoutSubviews
method, I change the size of the view to (300,250). This has worked in iOS 5/6/7 but no longer works in 8.
When the view is presented and a UITextField
is tapped, the app becomes unresponsive (not frozen, just not responding to touches). Almost as if the keyboard is presented but not appearing. Delegate methods ARE called correctly. If I remove the self.view.superview.bounds = CGRectMake(0, 0, 300, 250);
from the viewWillLayoutSubviews
method the keyboard works, but the view is now a full sized UIModalPresentationFormSheet
style.
This only happens in iOS 8, so I can only assume its an issue with the way the keyboard is presented and the way I am masking/resizing the view, but I'm at a loss as to the solution.
Presenting ViewController -
UserLoginViewController *loginVC = [[UserLoginViewController alloc] initWithNibName:@"UserLoginViewController" bundle:nil];
loginVC.modalPresentationStyle = UIModalPresentationFormSheet;
loginVC.delegate = self;
[self presentViewController:loginVC animated:YES completion:nil];
Editing the view bounds -
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
self.view.superview.layer.cornerRadius = 10.0;
self.view.superview.layer.masksToBounds = YES;
self.view.superview.bounds = CGRectMake(0, 0, 300, 250);
}
In iOS8 You shouldn't change superview bounds in viewWillLayoutSubviews because it causes infinite loop.
EDIT: in iOS8 property preferredContentSize works well.
You should change your code in that way:
Editing the view bounds -
Another way, which gives you more customization options is to use UIPresentationController and UIViewControllerTransitioningDelegate. Take a look at my code below.
Parent view controller:
AboutViewController.m
AboutTransitioningDelegate.h:
AboutTransitioningDelegate.m:
AboutPresentationController.h
AboutPresentationController.m
ProjectName-Prefix.pch
The simplest way to call
containerViewWillLayoutSubviews()
is to call: