From f28cc95e66c8da577d8156255768db4988822251 Mon Sep 17 00:00:00 2001 From: Parsifal Date: Mon, 29 May 2017 16:57:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?typo.=E2=80=99GreaterThen=20=3D>=20?= =?UTF-8?q?=E2=80=99GreaterThan=E2=80=99.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/UITableView+FDTemplateLayoutCell.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/UITableView+FDTemplateLayoutCell.m b/Classes/UITableView+FDTemplateLayoutCell.m index 7f26bd3..c74add0 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.m +++ b/Classes/UITableView+FDTemplateLayoutCell.m @@ -66,14 +66,14 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell { NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:contentViewWidth]; // [bug fix] after iOS 10.3, Auto Layout engine will add an additional 0 width constraint onto cell's content view, to avoid that, we add constraints to content view's left, right, top and bottom. - static BOOL isSystemVersionEqualOrGreaterThen10_2 = NO; + static BOOL isSystemVersionEqualOrGreaterThan10_2 = NO; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - isSystemVersionEqualOrGreaterThen10_2 = [UIDevice.currentDevice.systemVersion compare:@"10.2" options:NSNumericSearch] != NSOrderedAscending; + isSystemVersionEqualOrGreaterThan10_2 = [UIDevice.currentDevice.systemVersion compare:@"10.2" options:NSNumericSearch] != NSOrderedAscending; }); NSArray *edgeConstraints; - if (isSystemVersionEqualOrGreaterThen10_2) { + if (isSystemVersionEqualOrGreaterThan10_2) { // To avoid confilicts, make width constraint softer than required (1000) widthFenceConstraint.priority = UILayoutPriorityRequired - 1; @@ -93,7 +93,7 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell { // Clean-ups [cell.contentView removeConstraint:widthFenceConstraint]; - if (isSystemVersionEqualOrGreaterThen10_2) { + if (isSystemVersionEqualOrGreaterThan10_2) { [cell removeConstraints:edgeConstraints]; } From d69de7225460ffadf324dcdd7e38ae73a44e2b4e Mon Sep 17 00:00:00 2001 From: Parsifal Date: Mon, 29 May 2017 17:16:23 +0800 Subject: [PATCH 2/2] fix warning condition issue in iOS 10.3. --- Classes/UITableView+FDTemplateLayoutCell.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Classes/UITableView+FDTemplateLayoutCell.m b/Classes/UITableView+FDTemplateLayoutCell.m index c74add0..b1b1f99 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.m +++ b/Classes/UITableView+FDTemplateLayoutCell.m @@ -60,18 +60,19 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell { CGFloat fittingHeight = 0; + static BOOL isSystemVersionEqualOrGreaterThan10_2 = NO; + if (!cell.fd_enforceFrameLayout && contentViewWidth > 0) { // Add a hard width constraint to make dynamic content views (like labels) expand vertically instead // of growing horizontally, in a flow-layout manner. NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:cell.contentView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:contentViewWidth]; // [bug fix] after iOS 10.3, Auto Layout engine will add an additional 0 width constraint onto cell's content view, to avoid that, we add constraints to content view's left, right, top and bottom. - static BOOL isSystemVersionEqualOrGreaterThan10_2 = NO; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ isSystemVersionEqualOrGreaterThan10_2 = [UIDevice.currentDevice.systemVersion compare:@"10.2" options:NSNumericSearch] != NSOrderedAscending; }); - + NSArray *edgeConstraints; if (isSystemVersionEqualOrGreaterThan10_2) { // To avoid confilicts, make width constraint softer than required (1000) @@ -103,7 +104,9 @@ - (CGFloat)fd_systemFittingHeightForConfiguratedCell:(UITableViewCell *)cell { if (fittingHeight == 0) { #if DEBUG // Warn if using AutoLayout but get zero height. - if (cell.contentView.constraints.count > 0) { + // The contentView always gets 4 initial constraints in iOS 10.3. + NSUInteger initialConstraintCount = isSystemVersionEqualOrGreaterThan10_2 ? 4 : 0; + if (!cell.fd_enforceFrameLayout && cell.contentView.constraints.count > initialConstraintCount) { if (!objc_getAssociatedObject(self, _cmd)) { NSLog(@"[FDTemplateLayoutCell] Warning once only: Cannot get a proper cell height (now 0) from '- systemFittingSize:'(AutoLayout). You should check how constraints are built in cell, making it into 'self-sizing' cell."); objc_setAssociatedObject(self, _cmd, @YES, OBJC_ASSOCIATION_RETAIN_NONATOMIC);