From e53c91c22f09ec1451e5c33fdf6c0d0195486dee Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Fri, 1 Nov 2019 17:50:56 +0800 Subject: [PATCH] fix sometimes call layoutsubviews in cycle --- iOS/Pod/Classes/Shader/DoricLayouts.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iOS/Pod/Classes/Shader/DoricLayouts.m b/iOS/Pod/Classes/Shader/DoricLayouts.m index 2a6777d6..94426d91 100644 --- a/iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/iOS/Pod/Classes/Shader/DoricLayouts.m @@ -115,10 +115,12 @@ - (void)requestLayout { return; } self.waitingLayout = YES; + __weak typeof(self) _self = self; dispatch_async(dispatch_get_main_queue(), ^{ - self.waitingLayout = NO; + __strong typeof(_self) self = _self; [self sizeToFit]; [self layout]; + self.waitingLayout = NO; }); } @@ -127,6 +129,13 @@ - (void)layoutSubviews { [self requestLayout]; } +- (void)setNeedsLayout { + if (self.waitingLayout) { + return; + } + [super setNeedsLayout]; +} + - (void)layout { [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView *child, NSUInteger idx, BOOL *stop) { if ([child isKindOfClass:[DoricLayoutContainer class]]) {