2010-12-13 166 views
0

關於StackOverflow的第一個問題,請原諒我,如果我還沒有完成所有適當的步驟,儘管我已經嘗試搜索一段時間的答案了。在XCode中設置界面生成器對象座標

我試圖改變從界面生成器UIView中的多個對象的座標,當iPhone從縱向模式更改爲橫向模式。我不希望如此縮放視圖,但是當iPhone變爲橫向模式時,我想重新排列其中的對象,以便所有對象都能更好地適應。目前我正在尋找一種以編程方式設置X,Y座標的方法,但是如果有更好的方法去做這件事,請告訴我。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { 
    /* Move IBOutlets to different X,Y coordinates */ 

} 
return YES; 

回答

2

shouldAutorotateToInterfaceOrientation:應該只用於答案的觀點是否支持特定方向的問題。使用willRotateToInterfaceOrientation:didRotateFromInterfaceOrientation重新排列對象。

實際上,將子類UIView覆蓋並覆蓋layoutSubviews可能會更好。

+0

聽起來不錯,但我將如何最終改變這些對象的位置? – 2010-12-13 19:21:31

+0

假設您已經設立了IB網點(http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/IB_UserGuide/CodeIntegration/CodeIntegration.html#//apple_ref/doc/uid/TP40005344-CH18) ,只需設置對象的框架或中心,就像'self.myLabel.frame = CGRectMake(10,10,200,20)' – Brian 2010-12-13 19:40:23

+0

正是我在找的東西。謝謝! – 2010-12-13 19:44:12