iOS学习 --- cell的阴影渐变效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jiaxin_1105/article/details/80982537

今天无意中看到系统设置里, 点击cell跳转控制器时, 返回时cell的选中效果有个动画渐变效果


渐变效果.gif

实现过程

a.设置cell选中类型

cell.selectionStyle = UITableViewCellSelectionStyleDefault;
/** 其实三种效果感觉都一样的
    UITableViewCellSelectionStyleBlue,
    UITableViewCellSelectionStyleGray,
    UITableViewCellSelectionStyleDefault
 **/

b.设置Selected状态
在viewWillAppear方法中, 设置cell的Selected状态

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

   // 取出选中的indexPath
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    // 取出选中的cell
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    // 设置selected, 加上动画
    [cell setSelected:NO animated:YES];
}

c. 完成 (非常简单)


完成效果.gif

猜你喜欢

转载自blog.csdn.net/jiaxin_1105/article/details/80982537
今日推荐