代码之家  ›  专栏  ›  技术社区  ›  Uday Babariya

设置单元格动画时滚动(UITableview)时未检测到触摸

  •  0
  • Uday Babariya  · 技术社区  · 6 年前

    我为cell添加了一个动画。

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if indexPath.row > lastIndexPath.row{
            cell.animate(up: lastIndexPath.row < indexPath.row ? true : false)
            lastIndexPath = indexPath
        }
    }
    

    动画功能:

     func animate(up:Bool)  {
        self.alpha = 0
        let transform = CATransform3DTranslate(CATransform3DIdentity, 0, up ? 200 : -200 , 0)
        self.layer.transform = transform
    
        UIView.animate(withDuration: 0.4, delay: 0.05, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
            self.alpha = 1
            self.layer.transform = CATransform3DIdentity
        })
    }
    

    这个动画工作得很好,但问题是在滚动时,直到动画完成才检测到触摸。

    i、 如果我向上滚动,然后我想停止滚动,但由于动画,我无法在所需的单元格停止滚动。

    0 回复  |  直到 6 年前