2011-05-26 63 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

相关问题