我试图通过减少宽度和高度来在iPad上显示模态视图,但问题是它不是中心对齐的。在iOS 6中它曾经很好地工作,但在iOS 7中它不是中心对齐的。
以下是我的代码:
m_helpQA = [[HelpQAViewController alloc]init];
m_helpQA.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:m_helpQA animated:YES completion:NULL];
m_helpQA.view.superview.bounds = CGRectMake(0, 0, 350, 250);//Dimensions of ModalView.
目前我这样做了
答案 0 :(得分:1)
你需要将框架居中,这应该是可行的(我还没有测试过)。
CGRect appFrame = [UIScreen mainScreen].applicationFrame;
CGRect modalFrame = m_helpQA.view.superview.frame;
modalFrame.size = CGSizeMake(350.f, 250.f);
modalFrame.origin.x = appFrame.size.width/2.0f - modalFrame.size.width/2.0f;
modalFrame.origin.y = appFrame.size.height/2.0f - modalFrame.size.height/2.0f;
m_helpQA.view.superview.frame = modalFrame;
更新了代码以更正拼写错误
答案 1 :(得分:1)
对于iOS 7,请尝试:
[self.navigationController presentViewController:navigationController animated:YES completion:^{
//Make the modal bigger than normal
navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
}];
动画看起来很难看,所以我建议添加一个动画来改善它:
[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) {
}];
}];
另外请记住,您需要在viewDidAppear中设置navigationControllers视图的框架,以使内容的大小正确。
答案 2 :(得分:0)
尝试以下方法:
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
...
[self presentViewController:vc animated:NO completion:^{
vc.view.superview.center = self.view.window.center;
}];
// resize modal view
infoModalViewController.view.superview.bounds = CGRectMake(0, 0, newWidth, newHeight);
我必须在completition块中设置中心(在这种情况下是窗口的中心,但你也可以使用父视图控制器的中心)以使其正常工作。切换到animation:No
,否则会看起来很难看: - )