Skip to content

Commit

Permalink
fix bug:#41
Browse files Browse the repository at this point in the history
  • Loading branch information
TalkingJourney committed Dec 3, 2020
1 parent ddd140f commit 33620b5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions SCIndexView/SCIndexView.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static inline NSInteger SCPositionOfTextLayerInY(CGFloat y, CGFloat margin, CGFl

@interface SCIndexView ()

@property (nonatomic, strong) CAShapeLayer *searchLayer;
@property (nonatomic, strong, nullable) CAShapeLayer *searchLayer;
@property (nonatomic, strong) NSMutableArray<CATextLayer *> *subTextLayers;
@property (nonatomic, strong) UILabel *indicator;
@property (nonatomic, weak) UITableView *tableView;
Expand Down Expand Up @@ -65,7 +65,7 @@ - (void)layoutSubviews {

[CATransaction begin];
[CATransaction setDisableActions:YES];
if (self.searchLayer) {
if (self.searchLayer && !self.searchLayer.hidden) {
self.searchLayer.frame = CGRectMake(self.bounds.size.width - self.configuration.indexItemRightMargin - self.configuration.indexItemHeight, SCGetTextLayerCenterY(0, margin, space) - self.configuration.indexItemHeight / 2, self.configuration.indexItemHeight, self.configuration.indexItemHeight);
self.searchLayer.cornerRadius = self.configuration.indexItemHeight / 2;
self.searchLayer.contentsScale = UIScreen.mainScreen.scale;
Expand Down Expand Up @@ -94,12 +94,14 @@ - (void)configSubLayersAndSubviews
BOOL hasSearchLayer = [self.dataSource.firstObject isEqualToString:UITableViewIndexSearch];
NSUInteger deta = 0;
if (hasSearchLayer) {
self.searchLayer = [self createSearchLayer];
[self.layer addSublayer:self.searchLayer];
if (!self.searchLayer) {
self.searchLayer = [self createSearchLayer];
[self.layer addSublayer:self.searchLayer];
}
self.searchLayer.hidden = NO;
deta = 1;
} else if (self.searchLayer) {
[self.searchLayer removeFromSuperlayer];
self.searchLayer = nil;
self.searchLayer.hidden = YES;
}

NSInteger countDifference = self.dataSource.count - deta - self.subTextLayers.count;
Expand Down

0 comments on commit 33620b5

Please sign in to comment.