Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error to present view controller centered in iPad iOS 6

In iOS 5 it runs correctly:

PinRequiredViewController *pinView = [[PinRequiredViewController alloc]initWithNibName:@"PinRequiredView" bundle:nil];

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pinView];

            // show the navigation controller modally
            navController.modalPresentationStyle = UIModalPresentationFormSheet;
            navController.modalInPopover = NO;
            navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

            [self presentViewController:navController animated:YES completion:nil];

            navController.view.superview.frame = CGRectMake(0, 0, 250, 250);

            navController.view.superview.center = self.view.window.center;

But not working fine in iOS6, the view does not stay centered in the screen, both portrait and landscape. Any solutions?

Thanks!! :)

like image 514
Javi Campaña Avatar asked Sep 24 '12 11:09

Javi Campaña


3 Answers

I think it'll work if you remove the UIModalTransitionStyleFlipHorizontal transition style and use one of the other transition styles instead.

Seems like it's a bug with UIModalTransitionStyleFlipHorizontal.

like image 186
Tom Thorpe Avatar answered Sep 18 '22 12:09

Tom Thorpe


Use the completion: in your presentViewController:

[self presentViewController:navController animated:YES completion:^{
        navController.view.superview.bounds = CGRectMake(0, 0, 250, 250);}];

This will make it work with UIModalTransitionStyleFlipHorizontal.

like image 32
Pericles Avatar answered Sep 21 '22 12:09

Pericles


The problem is that you can set the frame of the superview to whatever you want but the origin will not be changed. That's the reason why it doesn't stay centered.

It looks like Apple restricted this on purpose in iOS6

like image 26
Adrian Florian Avatar answered Sep 19 '22 12:09

Adrian Florian