tableviewcell

时间:2017-04-21 12:22:26

标签: ios swift uitableview animation

对于我正在开发的应用,我使用了tableview。我的tableview,当然有tableviewcell。在那个tableviewcell中,我以编程方式添加视图(故事板中没有任何内容)。它是一个视图,我绘制一些线条和文本,这成为一个消息泡沫。如果您发送的其他用户也看到了消息气泡,则会打开一行气泡。

所以我在UIView的类中有动画函数(sendbubble.swift)

现在,它已经检查它是否被读取并且它打开了正确的气泡。但通常它应该在0.6秒内动画(打开的线应该旋转)。但它立即动画。所以我的问题是,如何用持续时间为它设置动画?

我还想在我的自定义UIView类(sendbubble.swift)中调用它。也许我需要在我的函数中使用代码来检查单元格是否出现在我的iphone上?

提前致谢!

func openMessage() {
    UIView.animate(withDuration: 0.6, delay: 0.0, options: [], animations: {
        var t = CATransform3DIdentity;
        t = CATransform3DMakeRotation(CGFloat(3 * Float.pi / 4), 0, 0, 1)
        self.moveableLineLayer.transform = t;
    }, completion:{(finished:Bool) in })
}

2 个答案:

答案 0 :(得分:0)

您需要实现UITableViewDelegate方法tableView(_:willDisplay:forRowAt:) https://developer.apple.com/reference/uikit/uitableviewdelegate/1614883-tableview

当要绘制单元格时触发它 - 而不是在创建单元格时触发。您还需要在模型中存储一个状态,说明动画是否已经发生,否则每次单元格重新进入视图时都会发生。

示例

在视图控制器(伪代码)

class CustomViewController: UITableViewDelegate {
    //where ever you define your tableview
    var tableView:UITableView
    tableView.delegate = self

    var dataSource //some array that is defining your cells - each object has a property call hasAnimated

    func tableView(_ tableView: UITableView, willDisplay cell: ITableViewCell, 
           forRowAt indexPath: IndexPath) {
        if let cell = cell as? CustomTableViewCell, dataSource[indexPath.row].hasAnimated == false {
            dataSource[indexPath.row].hasAnimated = true
            cell.openMessage()
        }
    }
}

class CustomTableViewCell: UITableViewCell {
    func openMessage() { //your method
    }
} 

答案 1 :(得分:0)

首先你需要抓住牢房。

  1. 获取需要显示开放气泡的单元格的indexPath。
  2. tableView.cellForRowAt(at:indexPath)
  3. 获取单元格
  4. 我们现在可以访问该气泡视图,现在您可以使用相同的功能进行动画处理func openMessage()
  5. 有任何问题吗?评价。