【发布时间】:2013-03-20 20:15:27
【问题描述】:
当我的应用处于横向与纵向模式时,我试图在不同位置显示一组图像。我已经搜索并找到了对willAnimateRotationToInterfaceOrientation:duration 方法的引用,我在其中添加了如下代码:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.getStartedImage1.frame = CGRectMake(5, 100, 155, 115);
self.getStartedImage2.frame = CGRectMake(160, 100, 155, 115);
self.getStartedImage3.frame = CGRectMake(315, 100, 155, 115);
}
else
{
self.getStartedImage1.frame = CGRectMake(238, 96, 155, 115);
self.getStartedImage2.frame = CGRectMake(238, 219, 155, 115);
self.getStartedImage3.frame = CGRectMake(238, 342, 155, 115);
}
}
这很有效,直到我意识到如果您在已经处于横向模式时进入视图,该方法将不会运行。这是有道理的,因为我在不旋转任何东西的情况下打开视图。但是,这对我的困境没有帮助。所以我继续搜索并找到了方法viewWillLayoutSubviews。我在这个方法中添加了相同的主体,它被调用了,但可能为时已晚,因为对图像帧的更改没有出现在模拟器中。如果我尝试将代码移动到viewWillAppear,我也会遇到同样的问题。我见过一些涉及多个视图的复杂解决方案,我宁愿避免。有什么建议吗?
【问题讨论】: