2013-07-22 37 views
0

我想要在設備處於橫向時爲320x240,縱向時爲240x320,屏幕中間爲UIViewiOS/UIKit:在旋轉過程中保持大小

例如:

Portrait Mode Landscape Mode


如果我讓UIKit中的佈局系統做它自己的,我得到這個旋轉時的景觀:

Bad Landscape 1

而且如果我試圖釘寬度和高度,我得到這個:

Bad Landscape 2


基本上,是有任何方式保持的物體的尺寸的旋轉期間(但仍旋轉對象)?最好只使用Interface Builder和/或最少量的代碼(如果這是不可能的話)。

+0

但是你的目標是*不*保持大小。您的目標是*將尺寸從320x240改爲240x320。 – rmaddy

+0

好點,我不知道如何正確地說出來。 – gvl

+0

您是否嘗試過從視圖控制器綁定到方向委託方法?從那裏,你可以根據方向調整你的子視圖的大小。 – JeffRegan

回答

0

我認爲傑夫康普頓是正確的:沒有辦法讓你改變你的視圖的大小給定的方向只使用XIB/Autolayouts/Autoresizing面具。

我認爲這樣做最簡單的方法是:

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    [UIView animateWithDuration:0.3 animations:^(void) { 
     if(UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) { 
      self.yourView.frame = CGRectMake([UIScreen mainScreen].frame.size.width-320/2,[UIScreen mainScreen].frame.size.height-240/2,320,240); 
     } else { 
      self.yourView.frame = CGRectMake([UIScreen mainScreen].frame.size.width-240/2,[UIScreen mainScreen].frame.size.height-320/2,240,320); 
     } 
    }]; 
} 
相關問題