Error to present view controller centered in iPad iOS 6

醉酒当歌 提交于 2019-12-21 12:24:49

问题


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!! :)


回答1:


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.




回答2:


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.




回答3:


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




回答4:


I succeeded with the following:

aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
aboutViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

CGRect aboutSheetFrame = aboutViewController.view.frame;
[self presentViewController:aboutViewController animated:YES completion:^{
        aboutViewController.view.superview.bounds = aboutSheetFrame;
        }];
aboutViewController.view.superview.bounds = aboutSheetFrame;

Use of UIModalTransitionStyleFlipHorizontal transition is still buggy on ios 6.1 beta 2. aboutSheetFrame is to avoid sizes hardcoding.




回答5:


In my understanding with UIModalTransitionStyleFlipHorizontal, the only wayout is by first presenting view without animation, setting the center point, after that in next line dismissing it and than again showing it with animated:yes. Like below.....

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

CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
navController.view.superview.center = centerPoint;
[navController dismissModalViewControllerAnimated:NO];

navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:navController animated:YES completion:nil]; 



回答6:


Just do it in viewDidAppear instead of viewDidLoad. And you're sorted !




回答7:


For iOS 7 try this:

[self.navigationController presentViewController:navigationController animated:YES completion:^{
    //Make the modal bigger than normal
    navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
}];

The animation will look ugly so I would recommend adding an animation to improve it:

[self.navigationController presentViewController:navigationController animated:YES completion:^{
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        //Make the modal bigger than normal
        navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
    } completion:^(BOOL finished) {
    }];
}];

Also remember that you will need to set the frame of the navigationControllers view in the viewDidAppear for the content to be the correct size.



来源:https://stackoverflow.com/questions/12563798/error-to-present-view-controller-centered-in-ipad-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!