在自定義的view中使用了[self layoutIfNeeded]方法,在iOS8\9上都沒有錯誤,可是在iOS7上出現了頁面錯亂,解決方案就是在自定義的view裏面添加以下代碼:blog
+ (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]; }