无法在iPad iOS6上的屏幕中央显示模态视图

时间:2013-08-04 04:59:17

标签: ios ipad ios6 modalviewcontroller uimodalpresentationformsh

我想在iPad屏幕上代表modalviewcontrollers有问题。如果我保持原样大小,那么它就完全集中了。但我对这些视图的信息很少,所以我需要调整它们的大小。

所以,当我调整它们的大小时,我不能强迫它们出现在屏幕中间。即使我设法将其中一个中心放在一个方向上,它也会在另一个方向上混乱。

这是我目前的代码:

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;

感谢任何帮助,谢谢。

4 个答案:

答案 0 :(得分:7)

这是一种适用于 iOS7 以及iOS 6和iOS5的方法,并且仍允许您使用 UIModalTransitionStyle Cover Vertical

-(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);
    }
}

答案 1 :(得分:4)

将您的最后一行更改为以下内容:

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

答案 2 :(得分:4)

不幸的是,停止在iOS7中工作。 只有将ModalTransitionStyle更改为Dissolve才能解决问题。也许这是iOS 7中的一个错误......

答案 3 :(得分:0)

在ios 7中你可以使用:

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

它有效。