【发布时间】:2014-05-30 04:44:40
【问题描述】:
当前情景:
现在我正在展示一个UIViewController,使用一个segue,样式为Modal,演示文稿Sheet。这个模态得到它的superview 边界变化,为了有我想要的尺寸,像这样:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.bounds = WHBoundsRect;
}
唯一允许的方向是UIInterfaceOrientationLandscapeLeft 和UIInterfaceOrientationLandscapeRight。由于 Modal 有一些 TextFields 并且键盘会在 Modal 本身上方,所以我正在更改它的 center,所以它会稍微移到顶部。
问题:
我现在注意到的是,我无法使用 Y 坐标。为了让它垂直移动(记住它是在横向上),我需要使用 X。问题是当它是 UIInterfaceOrientationLandscapeLeft 时,我需要使用负 X。当它是 UIInterfaceOrientationLandscapeRight 时,我需要使用正 X。因此,X/Y Coordinate System 似乎在纵向时“粘”在左上角,当出现方向时,它仍然存在:
我做了什么
所以我有这样的事情:
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
NSInteger newX = 0.0f;
if (orientation == UIInterfaceOrientationLandscapeLeft)
{
// Logic for calculating the negative X.
}
else
{
// Logic for calculating the positive X.
}
它的工作方式与我想要的完全一样,但它似乎是一个非常脆弱的实现。我错过了什么吗?这是预期的行为吗?
【问题讨论】:
-
你能解释一下你为什么要这样做 self.view.superview.bounds = WHBoundsRect;?
-
@AlessandroOrrù "这个 Modal 改变了它的 superview 边界,以便获得我想要的尺寸"
-
知道了,没看到模态视图和容器UIWindow之间有一个大小相同的超级视图
标签: ios uiviewcontroller uiinterfaceorientation