4

我想在iPad屏幕上显示的模态视图控制器有问题。如果我保持原来的大小,那么它都处于中心位置。但是我对这些观点的信息很少,所以我需要调整它们的大小。不能让模态视图出现在iPad屏幕的中心位置iOS6

因此,当我调整它们的大小时,我无法强制它们出现在屏幕中间。即使我设法将其中一个中心置于一个方向,也会混淆在另一个方向。

这里是我当前的代码:

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; 

希望得到任何帮助,谢谢。

+0

我试过你的代码(最后一行未注释掉),并且它在两个方向都很好地居中。你看到了什么结果? – rdelmar

+0

@rdelmar如果你在iPad上以纵向方向运行这段代码,它会显示居中,如果你从中旋转屏幕将保持居中。但!如果您首先在横向模式下运行它,那么即使您将屏幕旋转为纵向,它也会在屏幕中保持很低的水平。 – titicaca

回答

4

更改你的最后一行如下:

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

工程就像一个魅力!谢谢。我想我已经试过了,它没有工作,也许我做错了什么... – titicaca

+0

不工作,我试过你的代码 – Ranjit

4

停在iOS7工作,很遗憾。 只有将ModalTransitionStyle更改为Dissolve才能解决问题。也许这是在IOS 7中的错误...

7

下面是和上iOS7可以作为iOS6的和iOS5的方法,仍然允许您使用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); 
    } 
} 
+0

感谢psy!这在iOS7上是完美的! – drasick

0

在IOS 7你可以使用:

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

它的工作原理。

相关问题