实现tableView的左滑自定义事件及展示3D效果

1、创建tableView ,设置代理,实现两个必要的代理方法
2、实现代理

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
editingStyle = UITableViewCellEditingStyleDelete;//此处的EditingStyle可等于任意UITableViewCellEditingStyle,该行代码只在iOS8.0以前版本有作用,也可以不实现。

}
3、实现代理

  • (NSArray )tableView:(UITableView )tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
    {
UITableViewRowAction *  deleteRoWAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

//title可自已定义

    NSLog(@"点击删除");//事件
}];

//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义

UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
    
    NSLog(@"点击编辑");

}];



editRowAction.backgroundColor = [UIColor colorWithRed:0 green:124/255.0 blue:223/255.0 alpha:1];//可以定义RowAction的颜色


return @[deleteRoWAction, editRowAction];//最后返回这俩个RowAction 的数组

}

4、3D效果

  • (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

///配置 CATransform3D 动画内容
CATransform3D transform ;
transform.m34 = 1.0/-800;
//定义 Cell的初始化状态
cell.layer.transform = transform;
//定义Cell 最终状态 并且提交动画
[UIView beginAnimations:@"transform" context:NULL];
[UIView setAnimationDuration:1];
cell.layer.transform = CATransform3DIdentity;
cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
[UIView commitAnimations];

}

11.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容