Simulate tableViewCell click effect

Detailed introduction

When the width of the tableViewCell is changed, the width of his click effect does not change

You can write a simulation animation yourself

1 First turn off the click effect

self.selectionStyle=UITableViewCellSelectionStyleNone;

2. Override the two methods setSelected and setHighlighted 

// 配置cell选中状态
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
    [self setSelectedOrHighlighted:selected animated:animated];
}
// 配置cell高亮状态
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    [self setSelectedOrHighlighted:highlighted animated:animated];
}

-(void)setSelectedOrHighlighted:(BOOL)on animated:(BOOL)animated{
    if (animated) {
        [UIView animateWithDuration:0.4 animations:^{
            [self setSelectedOrHighlighted:on];
        }];
    }
    else{
        [self setSelectedOrHighlighted:on];
    }
}

-(void)setSelectedOrHighlighted:(BOOL)on{
    self.colorView.alpha=0.5*on;
}

 

Guess you like

Origin blog.csdn.net/Draven__/article/details/96338381