From 53da6ca3b519f007f8aad7e789bacd8b75664819 Mon Sep 17 00:00:00 2001 From: Joseph Lin Date: Mon, 26 Jun 2017 00:23:39 +0800 Subject: [PATCH] revert some code --- Classes/UITableView+FDTemplateLayoutCell.m | 60 ++++++++++++++++++- .../AppIcon.appiconset/Contents.json | 10 ++++ .../project.pbxproj | 8 ++- .../xcschemes/FDTemplateLayoutCell.xcscheme | 2 +- 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/Classes/UITableView+FDTemplateLayoutCell.m b/Classes/UITableView+FDTemplateLayoutCell.m index 7f26bd3..f8179d0 100644 --- a/Classes/UITableView+FDTemplateLayoutCell.m +++ b/Classes/UITableView+FDTemplateLayoutCell.m @@ -169,7 +169,65 @@ - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier configuration:( configuration(templateLayoutCell); } - return [self fd_systemFittingHeightForConfiguratedCell:templateLayoutCell]; + if ([UIDevice currentDevice].systemVersion.floatValue >= 10.3f) { + + return [self fd_systemFittingHeightForConfiguratedCell:templateLayoutCell]; + } + + CGFloat contentViewWidth = CGRectGetWidth(self.frame); + + // If a cell has accessory view or system accessory type, its content view's width is smaller + // than cell's by some fixed values. + if (templateLayoutCell.accessoryView) { + contentViewWidth -= 16 + CGRectGetWidth(templateLayoutCell.accessoryView.frame); + } else { + static const CGFloat systemAccessoryWidths[] = { + [UITableViewCellAccessoryNone] = 0, + [UITableViewCellAccessoryDisclosureIndicator] = 34, + [UITableViewCellAccessoryDetailDisclosureButton] = 68, + [UITableViewCellAccessoryCheckmark] = 40, + [UITableViewCellAccessoryDetailButton] = 48 + }; + contentViewWidth -= systemAccessoryWidths[templateLayoutCell.accessoryType]; + } + + CGSize fittingSize = CGSizeZero; + + if (templateLayoutCell.fd_enforceFrameLayout) { + // If not using auto layout, you have to override "-sizeThatFits:" to provide a fitting size by yourself. + // This is the same method used in iOS8 self-sizing cell's implementation. + // Note: fitting height should not include separator view. + SEL selector = @selector(sizeThatFits:); + BOOL inherited = ![templateLayoutCell isMemberOfClass:UITableViewCell.class]; + BOOL overrided = [templateLayoutCell.class instanceMethodForSelector:selector] != [UITableViewCell instanceMethodForSelector:selector]; + if (inherited && !overrided) { + NSAssert(NO, @"Customized cell must override '-sizeThatFits:' method if not using auto layout."); + } + fittingSize = [templateLayoutCell sizeThatFits:CGSizeMake(contentViewWidth, 0)]; + } else { + // Add a hard width constraint to make dynamic content views (like labels) expand vertically instead + // of growing horizontally, in a flow-layout manner. + if (contentViewWidth > 0) { + NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:templateLayoutCell.contentView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:contentViewWidth]; + [templateLayoutCell.contentView addConstraint:widthFenceConstraint]; + // Auto layout engine does its math + fittingSize = [templateLayoutCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; + [templateLayoutCell.contentView removeConstraint:widthFenceConstraint]; + } + } + + // Add 1px extra space for separator line if needed, simulating default UITableViewCell. + if (self.separatorStyle != UITableViewCellSeparatorStyleNone) { + fittingSize.height += 1.0 / [UIScreen mainScreen].scale; + } + + if (templateLayoutCell.fd_enforceFrameLayout) { + [self fd_debugLog:[NSString stringWithFormat:@"calculate using frame layout - %@", @(fittingSize.height)]]; + } else { + [self fd_debugLog:[NSString stringWithFormat:@"calculate using auto layout - %@", @(fittingSize.height)]]; + } + + return fittingSize.height; } - (CGFloat)fd_heightForCellWithIdentifier:(NSString *)identifier cacheByIndexPath:(NSIndexPath *)indexPath configuration:(void (^)(id cell))configuration { diff --git a/Demo/Demo/Images.xcassets/AppIcon.appiconset/Contents.json b/Demo/Demo/Images.xcassets/AppIcon.appiconset/Contents.json index 118c98f..b8236c6 100644 --- a/Demo/Demo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Demo/Demo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", diff --git a/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/project.pbxproj b/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/project.pbxproj index d950664..f696b0a 100644 --- a/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/project.pbxproj +++ b/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/project.pbxproj @@ -127,7 +127,7 @@ E19608C41BAD53AE00BDCBBE /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0830; TargetAttributes = { E19608CC1BAD53AF00BDCBBE = { CreatedOnToolsVersion = 7.0; @@ -189,8 +189,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -236,8 +238,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -267,6 +271,7 @@ E19608D61BAD53AF00BDCBBE /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -284,6 +289,7 @@ E19608D71BAD53AF00BDCBBE /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/xcshareddata/xcschemes/FDTemplateLayoutCell.xcscheme b/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/xcshareddata/xcschemes/FDTemplateLayoutCell.xcscheme index f9edfe9..c4a08f6 100644 --- a/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/xcshareddata/xcschemes/FDTemplateLayoutCell.xcscheme +++ b/FDTemplateLayoutCell/FDTemplateLayoutCell.xcodeproj/xcshareddata/xcschemes/FDTemplateLayoutCell.xcscheme @@ -1,6 +1,6 @@