Search code examples
iosipadios6modalviewcontrolleruimodalpresentationformsh

Can't make modal view appear right in the center of the screen on iPad iOS6


I have a problem with modalviewcontrollers that I want to represent on iPad screen. If I leave the size as it is, then it's all centred fine. But I have very few info on these views, so I need to resize them.

So, when I resize them, I can't force them to appear in the middle of the screen. Even if I manage to center one of them in one orientation, it's messed up in other one.

Here is my current code:

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:acvc];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[nav setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
[[acvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"main_bg.jpg"]]];
[self presentViewController:nav animated:YES completion:nil];
nav.view.superview.frame = CGRectMake(self.view.bounds.size.width/2 + 175, self.view.bounds.size.height/2 - 125, 350, 250);
// nav.view.superview.center = self.view.window.center;

Would appreciate any help, thank you.


Solution

  • Change your last line to the following:

    nav.view.superview.bounds = CGRectMake(0, 0, 350, 250);