autolayout在iOS10中的问题

375 阅读1分钟

有段时间没有写代码了.最近在帮朋友做一个项目.发现了以前自己写的基类cell在iOS 10中会出现不少约束错误.自动布局 下面是iOS 10之前的

[self.contentView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeBottom];
[self.contentView autoSetDimension:ALDimensionWidth toSize:self.frame.size.width];

以前只用约束一下上,左,右和宽度就可以但是在iOS 10中 如果不约束下方的话.就会报一大堆约束错误,所以改代码为:

if ([[[UIDevice currentDevice] systemVersion] floatValue]>=10.0) {
[self.contentView autoPinEdgesToSuperviewEdges];
}else{
[self.contentView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeBottom];
[self.contentView autoSetDimension:ALDimensionWidth toSize:self.frame.size.width];
}

完美解决

后来查询资料得知.iOS 10修改了layoutifneed的bug.导致了这一情况的发生 另外iOS 10已经取消的设置的跳转,所以以前的一篇文章基本作废. 但是10以下的系统还是可以用的 连接如下:

http://www.jianshu.com/p/12121795eb3a