我試圖在我的應用處於橫向模式或縱向模式時在不同位置顯示一組圖像。我已經搜查,發現參考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