Skip to content

Commit 51b8385

Browse files
committed
iOS 14 fixes from CEWendel#434
1 parent a8a20f8 commit 51b8385

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

SWTableViewCell/PodFiles/SWTableViewCell.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef NS_ENUM(NSInteger, SWCellState)
4141
@property (nonatomic, copy) NSArray *rightUtilityButtons;
4242

4343
@property (nonatomic, weak) id <SWTableViewCellDelegate> delegate;
44+
@property (nonatomic, strong) UIView *contentCellView;
4445

4546
- (void)setRightUtilityButtons:(NSArray *)rightUtilityButtons WithButtonWidth:(CGFloat) width;
4647
- (void)setLeftUtilityButtons:(NSArray *)leftUtilityButtons WithButtonWidth:(CGFloat) width;

SWTableViewCell/PodFiles/SWTableViewCell.m

+24-25
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#import "SWTableViewCell.h"
1010
#import "SWUtilityButtonView.h"
1111

12-
static NSString * const kTableViewCellContentView = @"UITableViewCellContentView";
13-
1412
#define kSectionIndexWidth 15
1513
#define kAccessoryTrailingSpace 15
1614
#define kLongPressMinimumDuration 0.16f
@@ -47,7 +45,7 @@ @implementation SWTableViewCell {
4745
UIView *_contentCellView;
4846
BOOL layoutUpdating;
4947
}
50-
48+
@synthesize contentCellView = _contentCellView;
5149
#pragma mark Initializers
5250

5351
- (instancetype)initWithCoder:(NSCoder *)aDecoder
@@ -89,27 +87,29 @@ - (void)initializer
8987
[self.cellScrollView addSubview:_contentCellView];
9088

9189
// Add the cell scroll view to the cell
92-
UIView *contentViewParent = self;
90+
UIView *contentViewParent = _contentCellView;
9391
UIView *clipViewParent = self.cellScrollView;
94-
if (![NSStringFromClass([[self.subviews objectAtIndex:0] class]) isEqualToString:kTableViewCellContentView])
95-
{
96-
// iOS 7
97-
contentViewParent = [self.subviews objectAtIndex:0];
98-
clipViewParent = self;
99-
}
92+
10093
NSArray *cellSubviews = [contentViewParent subviews];
101-
[self insertSubview:self.cellScrollView atIndex:0];
94+
[self.contentView insertSubview:self.cellScrollView atIndex:0];
10295
for (UIView *subview in cellSubviews)
10396
{
10497
[_contentCellView addSubview:subview];
10598
}
10699

107100
// Set scroll view to perpetually have same frame as self. Specifying relative to superview doesn't work, since the latter UITableViewCellScrollView has different behaviour.
108-
[self addConstraints:@[
109-
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
110-
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
111-
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0],
112-
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0],
101+
[self.contentView addConstraints:@[
102+
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
103+
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
104+
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0],
105+
[NSLayoutConstraint constraintWithItem:self.cellScrollView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0],
106+
]];
107+
108+
[self.cellScrollView addConstraints:@[
109+
[NSLayoutConstraint constraintWithItem:_contentCellView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.cellScrollView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
110+
[NSLayoutConstraint constraintWithItem:_contentCellView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.cellScrollView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
111+
[NSLayoutConstraint constraintWithItem:_contentCellView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.cellScrollView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0],
112+
[NSLayoutConstraint constraintWithItem:_contentCellView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.cellScrollView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0],
113113
]];
114114

115115
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewTapped:)];
@@ -127,13 +127,13 @@ - (void)initializer
127127
// Such an approach is necessary in order for the utility views to sit on top to get taps, as well as allow the backgroundColor (and private UITableViewCellBackgroundView) to work properly.
128128

129129
self.leftUtilityClipView = [[UIView alloc] init];
130-
self.leftUtilityClipConstraint = [NSLayoutConstraint constraintWithItem:self.leftUtilityClipView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
130+
self.leftUtilityClipConstraint = [NSLayoutConstraint constraintWithItem:self.leftUtilityClipView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_cellScrollView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
131131
self.leftUtilityButtonsView = [[SWUtilityButtonView alloc] initWithUtilityButtons:nil
132132
parentCell:self
133133
utilityButtonSelector:@selector(leftUtilityButtonHandler:)];
134134

135135
self.rightUtilityClipView = [[UIView alloc] initWithFrame:self.bounds];
136-
self.rightUtilityClipConstraint = [NSLayoutConstraint constraintWithItem:self.rightUtilityClipView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0];
136+
self.rightUtilityClipConstraint = [NSLayoutConstraint constraintWithItem:self.rightUtilityClipView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0];
137137
self.rightUtilityButtonsView = [[SWUtilityButtonView alloc] initWithUtilityButtons:nil
138138
parentCell:self
139139
utilityButtonSelector:@selector(rightUtilityButtonHandler:)];
@@ -157,23 +157,22 @@ - (void)initializer
157157
clipView.clipsToBounds = YES;
158158

159159
[clipViewParent addSubview:clipView];
160-
[self addConstraints:@[
160+
[self.contentView addConstraints:@[
161161
// Pin the clipping view to the appropriate outer edges of the cell.
162-
[NSLayoutConstraint constraintWithItem:clipView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
163-
[NSLayoutConstraint constraintWithItem:clipView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
164-
[NSLayoutConstraint constraintWithItem:clipView attribute:alignmentAttribute relatedBy:NSLayoutRelationEqual toItem:self attribute:alignmentAttribute multiplier:1.0 constant:0.0],
162+
[NSLayoutConstraint constraintWithItem:clipView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
163+
[NSLayoutConstraint constraintWithItem:clipView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
164+
[NSLayoutConstraint constraintWithItem:clipView attribute:alignmentAttribute relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:alignmentAttribute multiplier:1.0 constant:0.0],
165165
clipConstraint,
166166
]];
167167

168168
[clipView addSubview:buttonView];
169-
[self addConstraints:@[
169+
[clipView addConstraints:@[
170170
// Pin the button view to the appropriate outer edges of its clipping view.
171171
[NSLayoutConstraint constraintWithItem:buttonView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:clipView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0],
172172
[NSLayoutConstraint constraintWithItem:buttonView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:clipView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0],
173173
[NSLayoutConstraint constraintWithItem:buttonView attribute:alignmentAttribute relatedBy:NSLayoutRelationEqual toItem:clipView attribute:alignmentAttribute multiplier:1.0 constant:0.0],
174174

175175
// Constrain the maximum button width so that at least a button's worth of contentView is left visible. (The button view will shrink accordingly.)
176-
[NSLayoutConstraint constraintWithItem:buttonView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.contentView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:-kUtilityButtonWidthDefault],
177176
]];
178177
}
179178
}
@@ -601,7 +600,7 @@ - (void)updateCellState
601600
}
602601

603602
// Update the clipping on the utility button views according to the current position.
604-
CGRect frame = [self.contentView.superview convertRect:self.contentView.frame toView:self];
603+
CGRect frame = [_cellScrollView convertRect:_contentCellView.frame toView:self];
605604
frame.size.width = CGRectGetWidth(self.frame);
606605

607606
self.leftUtilityClipConstraint.constant = MAX(0, CGRectGetMinX(frame) - CGRectGetMinX(self.frame));

0 commit comments

Comments
 (0)