调整ModalViewController的大小并将其放置在iOS 7的中心位置 [英] Resize ModalViewController and position it at center in iOS 7

查看:129
本文介绍了调整ModalViewController的大小并将其放置在iOS 7的中心位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过减少iPad的宽度和高度来显示iPad上的modalView,但问题是它不是中心对齐的。在iOS 6中它过去工作正常,但在iOS 7中它不是中心对齐的。

I am trying to show a modalView on an iPad by reducing its width and height, but the problem is that it is not center-aligned. In iOS 6 it used to work fine, but in iOS 7 it is not center aligned.

以下是我的代码:

 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.

目前我这样做了

推荐答案

你需要将框架居中,这应该是可行的(我还没有测试过)。

You need to center the frame something like this should work (I haven't tested).

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;

更新代码以更正拼写错误

Updated Code to correct typo

这篇关于调整ModalViewController的大小并将其放置在iOS 7的中心位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆