UItableViewCell的动画swift版

tableViewCell的动画效果

看到很多APP的tableViewCel在从屏幕外进入屏幕的时候会有很炫的动画,就找资料写了一个demo,非常炫酷,也非常实用

  • 先看下实现的效果吧,有两种动画效果

cell动画

  • 下面开始正式内容 1.创建工程,添加2个ViewController,实现NavigationController跳转 2.红色cell的动画效果,需要重写viewWillAppear方法,在viewWillAppear方法中将所有的cell移动到屏幕外边,并且设置动画
override func viewWillAppear(animated: Bool) {
    // tableView重新加载视图
   self.tableView.reloadData()
    // 获取tableView所有的cell的数组
   let cells = self.tableView.visibleCells
   for cell in cells {
        // 将每个cell移动到屏幕外
       cell.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height)
    }
    // 将每个cell移动到自己的位置,并且根据cell的index设置延时
    for (index, cell) in cells.enumerate() {
        UIView.animateWithDuration(1, delay: 0.05 * Double(index), options: .CurveLinear, animations: { () -> Void in
        cell.transform = CGAffineTransformMakeTranslation(0, 0)
        }, completion: { (finished) -> Void in     
        })
    }    
}

3.绿色cell 的动画效果,这个动画效果我们需要在willDisplayCell的代理方法中实现,并且需要用到UIview的简单动画

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
    // 设置大小缩放
     let trans = CATransform3DMakeScale(0.1, 0.1, 0.1)
    // 在大小缩放的基础上设置旋转
     cell.layer.transform = CATransform3DRotate(trans, CGFloat(M_PI_2), 0, 0, 1)
     UIView.animateWithDuration(1) { () -> Void in
        // 动画实现将cell的layer复原
         cell.layer.transform = CATransform3DIdentity
     }
    // 最后复原cell的frame
     cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);    
}

转载于:https://my.oschina.net/ozawa4865/blog/714906

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值