2011-05-26 64 views
0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)){ 
     Add1.contentStretch=CGRectMake(0.00,0.00,1024.00,66.00); 
     background.image = [UIImage imageNamed:@"back2-landscape.png"]; 
    } else if((self.interfaceOrientation == UIDeviceOrientationPortrait) || (self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)){ 
     Add1.contentStretch=CGRectMake(0.00,0.00,768.00,66.00); 
     background.image = [UIImage imageNamed:@"back2-portrait.png"]; 
    } 
    // Return YES for supported orientations 
    return YES; 
} 

在這段代碼中,我在點方案獲得EXC_BAD_ACCESS爲InterfaceOrientation

if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight)) 

得到EXC_BAD_ACCESS請告訴我爲什麼我收到此錯誤?

回答

0

雞和蛋的問題
你不應該訪問interfaceOrientation屬性裏面shouldAutorotateToInterfaceOrientation:方法,因爲它會創建一個週期。不知道爲視圖控制器啓用了哪個接口方向,視圖控制器無法明確地告訴你它的方向是什麼(不要將其與設備的方向相混淆),但是在這裏您使用與用於圖形相同的方法調用它取出它的方向。所以它創建了一個導致崩潰的無限循環。

你不應該在這個方法中做你的佈局。看看layoutSubviews

+0

謝謝迪帕克。 – Lena 2011-05-27 04:10:13

+0

但它如何在iPhone上工作呢? – 2012-03-01 03:27:06

+0

以及如何在UIViewController中使用layoutSubviews? – 2012-03-01 03:53:55

相關問題