2013-09-26 46 views
0

我工作的一個iPhone應用程序,我想創造縱向視圖和橫向視圖獨立的佈局。在縱向佈局中,我有2列3行方形按鈕(這是在界面生成器中用xib完成的)。在景觀我想有3列2行。這可能嗎?我添加了下面的代碼,我認爲可以爲此工作。創建單獨的縱向和橫向佈局的iPhone

- (void)willAnimateRotationToInterfaceOrientation:  
(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
    toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    NSLog(@"Landscape Rotation Occurred"); 
    scriptureButton.frame = CGRectMake(20, 20, 130, 130); 
    characterSketchButton.frame = CGRectMake(170, 20, 130, 130); 
    mapButton.frame = CGRectMake(320, 20, 130, 130); 
    storyingButton.frame = CGRectMake(20, 170, 130, 130); 
    videoButton.frame = CGRectMake(170, 170, 130, 130); 
    otherResourcesButton.frame = CGRectMake(320, 170, 130, 130); 
} 
else 
{ 
    NSLog(@"Portrait Rotation Occurred"); 
    scriptureButton.frame = CGRectMake(20, 20, 130, 130); 
    characterSketchButton.frame = CGRectMake(170, 20, 130, 130); 
    mapButton.frame = CGRectMake(20, 170, 130, 130); 
    storyingButton.frame = CGRectMake(170, 170, 130, 130); 
    videoButton.frame = CGRectMake(20, 320, 130, 130); 
    otherResourcesButton.frame = CGRectMake(170, 320, 130, 130); 
} 
} 

回答

0

的一般有兩種方法來手動實現此 -

  1. 將您的意見作爲自己的代碼一樣。關於它本身並沒有什麼壞處,但請注意它需要在視圖(而不是視圖控制器)layoutSubviews中完成。您在視圖之前設置的任何框架都將顯示其子視圖,並將在該過程中通過自動佈局進行重置。

  2. 有兩個控制器和具有例如在轉換過程中,人像會自動顯示並消除風景。

由於可以使用自動佈局和界面生成器的所有細微照常進行建模在第二種方法中,這通常被認爲是優選的。

雖然也可以使用1:1的變型中,通過直接改變不是幀,而是視圖上的佈局約束如果由於某種原因兩控制器解決方案是不可接受的。

但是,從你的問題,它實際上聽起來像你需要一個UICollectionView。一旦設置了單元大小,它將在視圖控制器的邊界更改期間根據需要重新定位其單元。

+0

感謝您的建議。我去了Collection View,這是我之前考慮過的。 – James