[一系列if語句將backgroundImage設置爲[UIImageNamed @「Background-Default-Landscape」];我是正確的假設,該設備將尋找名爲[email protected]的文件,如果它是一個Retina顯示屏?]
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
CGRect containerRect = CGRectZero;
containerRect.size = [backgroundImage size];
UIView *containerView = [[UIView alloc] initWithFrame:containerRect];
[containerView addSubview:backgroundView];
現在我的應用程序啓動,一旦加載顯示一個白色屏幕,而不是指定的背景(沒有背景是純白色的)。
在我開始把東西放在的背景之前,我在缺少什麼東西來繪製背景?
感謝,
- 編輯 -
至於代碼,我有:
- (void) renderScreen
{
int height = [[UIScreen mainScreen] bounds].size.height;
int width = [[UIScreen mainScreen] bounds].size.width;
UIImage *backgroundImage = nil;
if (height == 2048 || height == 2008 || height == 1024 || height == 1004 || height == 984)
{
backgroundImage = [UIImage imageNamed:@"Background-Default-Portrait"];
}
// Other such statements cut.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
CGRect containerRect = CGRectZero;
containerRect.size = [backgroundImage size];
UIView *containerView = [[UIView alloc] initWithFrame:containerRect];
[containerView addSubview:backgroundView];
[self.view addSubview:containerView];
然後下面是報表上繪製背景。當它旋轉
該方法被調用時的初始視圖載荷和:
- (void)viewDidLoad
{
[super viewDidLoad];
[self renderScreen];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(renderScreen) name:UIDeviceOrientationDidChangeNotification object:nil];
}
的行爲是正確的初始畫面加載,然後它消失爲白色,沒有什麼有趣的似乎後,這種情況發生。
- 編輯 -
在頂部,我有:
int height = [[UIScreen mainScreen] bounds].size.height;
int width = [[UIScreen mainScreen] bounds].size.width;
當我的NSLog的高度和寬度,在橫向模式視網膜設備,我得到的1024的高度和寬度爲768.顯示的圖像是肖像圖像的旋轉;如果我將設備轉到側面,則圖像會整齊地填滿整個屏幕,但背景會顯示水平擠壓的圖像。
我應該做任何不同的事情來正確地獲得高度和寬度?我希望在橫向的設備的高度將是768,寬度是1024
這一切似乎都是正確的。我們需要看到更多的代碼。你在哪種方法中添加視圖?並添加'containerView'到哪個視圖? –
你能把更多的代碼?我建議你將containerView添加到self.view中。此外,非視網膜圖像是Default-Background-Labdscape.png(帶有.png擴展名)。 – RFG
@GuyKogus,謝謝你;我在代碼中添加了更多的上下文。 – JonathanHayward