[英]Change background image on ipad after rotation
我使用UIImageView
顯示應用程序的背景色。 為了支持正確的接口旋轉,我編寫layoutSubviews
方法。 在此方法中,.frame屬性正確更改,但是當我嘗試更改UIImageView
圖像時,如下所示:
view = [self viewWithTag:1002];
((UIImageView *)view).image = [UIImage imageNamed:@"portrait.png"];
沒有改變。 我做錯了什么還是無法在layoutSubviews
方法中更改UIImageView
圖像?
嘗試這個
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// change background here
}
您可以使用UIViewController管理視圖的旋轉(請確保在此處簽出文檔: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html ) 。 如果為UIImageView實現了UIViewController ,則可以在viewDidLoad:
方法中設置圖像。
您不應覆蓋layoutSubviews:
方法來執行此操作。 layoutSubviews:
按照名稱中的說明進行操作-它應該執行該視圖當前具有的所有子子視圖的定位和大小調整。 除非您想對子視圖進行一些特殊的自定義布局,並且在UIView設置為“需要調整大小”時在運行循環中被調用,否則您不需要重寫此方法。
我強烈建議您從代碼中的其他位置設置圖像。 如果要在旋轉視圖時更改圖像,則可以在UIViewController子類的- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
方法中設置圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.