首先,內容模式(與setContentMode:
或通過改變視圖在IB模式設置)是不會對你有用,因爲它控制是什麼反應發生在一個視圖的內容到一個改變大小 - 它不能控制實際的大小變化。更重要的是,除非將其設置爲UIViewContentModeRedraw
,否則內容不會重新繪製,而只是移位或拉伸,這通常不是您想要的。
另一方面,設置自動調整大小(或使用IB中的自動調整大小框)並不能達到您想要的效果。 UIViewAutoresizingFlexibleWidth
將根據超視圖尺寸的che變化成比例地改變視圖的寬度(使用UIViewAutoresizingFlexibleLeftMargin
和/或UIViewAutoresizingFlexibleLeftMargin
此外還將控制屏幕兩側的距離是否保持不變)。但是自動調整面具並沒有給你一種方法來改變寬度的變化:根據改變寬度:你可以根據超級視圖的高度和/或堅持頂部/底部來改變高度。
所以你必須要管理自己的調整,編程,在willRotateToInterfaceOrientation:duration:
。喜歡的東西:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect rectToResizeTo;
if ((toInterfaceOrientation == UIInterfaceOrientationPortrait) || (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) {
rectToResizeTo = CGRectMake(x1, y1, width1, height1);
} else {
rectToResizeTo = CGRectMake(x2, y2, width2, height2);
}
[UIView animateWithDuration:duration animations:^{
self.viewToResize.frame = rectToResizeTo;
}];
}
這已經涵蓋以下鏈接 - http://stackoverflow.com/questions/2325795/webview-resizes-automatically-to-portrait-and-landscape-view-in-iphone – iOSPawan 2012-02-08 09:01:28
感謝您的評論。它可能不適用於我的情況,因爲我的UIView是在IB中創建的。但我會試試看... – Stanley 2012-02-08 09:07:01
不幸的是,問題2325765的解決方案並沒有爲我工作。當應用autoresizingMask時,圖像會縮小得更多。 – Stanley 2012-02-08 09:19:38