在自定义的view中使用了[self layoutIfNeeded]方法,在iOS89上都没有错误,但是在iOS7上出现了页面错乱,解决方案就是在自定义的view里面添加如下代码:
+ (void)load { Method existing = class_getInstanceMethod(self, @selector(layoutSubviews)); Method new = class_getInstanceMethod(self, @selector(_autolayout_replacementLayoutSubviews)); method_exchangeImplementations(existing, new); } - (void)_autolayout_replacementLayoutSubviews { [super layoutSubviews]; [self _autolayout_replacementLayoutSubviews]; // not recursive due to method swizzling [super layoutSubviews]; }