Popover with ModalPresentationStyle is not centered in iOS 7 iPad Popover with ModalPresentationStyle is not centered in iOS 7 iPad objective-c objective-c

Popover with ModalPresentationStyle is not centered in iOS 7 iPad


I had the same problem. I have solved this by using another approach, found here.

What this solution proposes is to use the method (void)viewWillLayoutSubviews

So in case of @Manuel M. inside the GeneralSettingsViewController add the code below:

// GeneralSettingsViewController- (void)viewWillLayoutSubviews{    [super viewWillLayoutSubviews];    self.view.superview.bounds = CGRectMake(0, 0, 497, 375);}

And you won't need this code anymore:

self.generalSettingsVC.view.superview.frame = CGRectMake(0, 0, 497, 375);self.generalSettingsVC.view.superview.center = self.view.center;

For @titicaca, you are using a UINavigationController I haven't test it with this Controller but you could try the same solution I mentioned, extending the UINavigationController and overwrite the viewWillLayoutSubviews method.

[EDIT]

For @titicaca I tried it in a new project and for me it worked. What I did was having a custom navigation view controller CustomNavigationController overriding the viewWillLayoutSubviewslike this:

- (void)viewWillLayoutSubviews{    [super viewWillLayoutSubviews];    self.view.superview.bounds = CGRectMake(0, 0, 330, 284);}

Then, the view controller that presents the CustomNavigationController should execute a code similar to this:

UIViewController *myVC = [[UIViewController alloc] init];[myVC.view setBackgroundColor:[UIColor redColor]];CustomNavigationController *nav = [[CustomNavigationController alloc] initWithRootViewController:myVC];[nav setModalPresentationStyle:UIModalPresentationFormSheet];[nav setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];[self presentViewController:nav animated:YES completion:nil];

You need to make sure though, that the dimensions of the self.view.superview.bounds = CGRectMake(0, 0, 330, 284); are even numbers otherwise the text inside gets fuzzy, if there is any


For me the issue was calling becomeFirstResponder on a text field in the viewDidAppear of the presented view controller. Appears to be a bug with that now. The solution was wrapping it in a simple dispatch_async:

- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    dispatch_async(dispatch_get_main_queue(), ^{        [self.userNameTextField becomeFirstResponder];    });}


It's the same for me... I don't know yet how to solve it. I'm currently working in that issue so anything I get I'll share it!

This is my code.

-(IBAction)showGeneralSettings:(id)sender{self.generalSettingsVC = [[GeneralSettingsViewController alloc] initWithNibName:@"GeneralSettingsView" bundle:nil];//Present the view controller as a modal with a custom size (important to do after presenting it)self.generalSettingsVC.modalPresentationStyle = UIModalPresentationFormSheet;[self presentViewController:self.generalSettingsVC animated:YES completion:nil];self.generalSettingsVC.view.superview.frame = CGRectMake(0, 0, 497, 375);self.generalSettingsVC.view.superview.center = self.view.center;

}