如何解决程序收到EXC_BAD_ACCESS用于InterfaceOrientation
|| - (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,768.00,66.00);
background.image = [UIImage imageNamed:@\"back2-portrait.png\"];
}
// Return YES for supported orientations
return YES;
}
在这段代码中,我得到了EXC_BAD_ACCESS
if((self.interfaceOrientation == UIDeviceOrientationLandscapeLeft) || (self.interfaceOrientation == UIDeviceOrientationLandscapeRight))
请告诉我为什么会出现此错误?
解决方法
鸡肉和鸡蛋问题
您不应该在
shouldAutorotateToInterfaceOrientation:
方法内部访问interfaceOrientation
属性,因为它会创建一个循环。在不知道为视图控制器启用了哪些接口方向的情况下,视图控制器无法确切地告诉您它的方向是什么(不要将此与设备的方向相混淆),但是在这里您需要在用来确定其方向的相同方法。因此,它创建了一个无限循环,导致崩溃。
您不应该使用这种方法进行布局。看layoutSubviews
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。