我试图在我的应用处于横向模式或纵向模式时在不同位置显示一组图像。我已经搜查,发现参考willAnimateRotationToInterfaceOrientation:duration
方法,在这里我补充这样的代码:ios:基于方向的移动图像
- (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
,我也遇到同样的问题。我看到了一些涉及多个视图的复杂解决方案,我宁愿避免。有什么建议么?
谢谢。我现在用#2去了。我无法关闭自动布局,因为它对我的其他视图至关重要,我不确定我完全理解#3。你的意思是删除有关图像的限制吗? – 2013-03-20 21:38:18
@CherylYaeger我添加了一些关于选项3的更多信息。 – NJones 2013-03-21 02:13:20
感谢您添加这些额外的信息! – 2013-04-02 18:33:41