Merge branch 'feature/fix_iOS_layout_container' into 'master'

fix sometimes call layoutsubviews in cycle



See merge request !5
This commit is contained in:
pengfeizhou 2019-11-01 17:51:32 +08:00
commit cea067f81f

View File

@ -115,10 +115,12 @@ - (void)requestLayout {
return; return;
} }
self.waitingLayout = YES; self.waitingLayout = YES;
__weak typeof(self) _self = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
self.waitingLayout = NO; __strong typeof(_self) self = _self;
[self sizeToFit]; [self sizeToFit];
[self layout]; [self layout];
self.waitingLayout = NO;
}); });
} }
@ -127,6 +129,13 @@ - (void)layoutSubviews {
[self requestLayout]; [self requestLayout];
} }
- (void)setNeedsLayout {
if (self.waitingLayout) {
return;
}
[super setNeedsLayout];
}
- (void)layout { - (void)layout {
[self.subviews enumerateObjectsUsingBlock:^(__kindof UIView *child, NSUInteger idx, BOOL *stop) { [self.subviews enumerateObjectsUsingBlock:^(__kindof UIView *child, NSUInteger idx, BOOL *stop) {
if ([child isKindOfClass:[DoricLayoutContainer class]]) { if ([child isKindOfClass:[DoricLayoutContainer class]]) {