Unable to make a modal look right in the center of the screen of an iPad iOS6

I have a problem with modalviewcontrollers that I want to present on the iPad screen. If I leave the size as it is, then it will all be well focused. But I have very little information about these views, so I need to resize them.

So, when I resize them, I cannot make them appear in the middle of the screen. Even if I manage to concentrate one of them in one orientation, she messed up in another.

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; 

Thanks any help, thanks.

+4
source share
4 answers

Change your last line to the following:

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

It uses the iOS7 method, as well as iOS6 and iOS5, and still allows the use of UIModalTransitionStyleCoverVertical :

 -(void)presentController:(UIViewController*)controller fromRootController:(UIViewController*)rootController withSize:(CGSize)size { UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller]; nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical; nav.modalPresentationStyle = UIModalPresentationFormSheet; [rootController presentModalViewController:nav animated:YES]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { nav.view.superview.backgroundColor = [UIColor clearColor]; nav.view.bounds = CGRectMake(0, 0, size.width, size.height); } else { nav.view.superview.bounds = CGRectMake(0, 0, size.width, size.height); } } 
+7
source

Unfortunately, it stopped working in iOS7. The only problem is changing the ModalTransitionStyle to Dissolve. Perhaps this is a bug in iOS 7 ...

+4
source

in ios 7 you can use:

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

it works.

0
source

Source: https://habr.com/ru/post/1495162/


All Articles