如何在Xamarin iOS中从底部到顶部的UITableViewCell过渡动画?

时间:2017-10-18 13:12:58

标签: ios uitableview animation xamarin

如何在Xamarin iOS原生中从底部到顶部设置UITableViewCell过渡动画?

大家都是Xamarin iOS原生社区,我正在寻找一种在UITableView中为UITableViewCell制作动画的方法,创建一个从底部到顶部的过渡,对任何单元格都有淡入淡出效果。

enter image description here

因为我找到的所有示例都在Swift中,所以我自己解决了这个问题,我将为社区分享解决方案。

3 个答案:

答案 0 :(得分:2)

迅速4并解决滚动问题:

private var finishedLoadingInitialTableCells = false
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

    var lastInitialDisplayableCell = false

    //change flag as soon as last displayable cell is being loaded (which will mean table has initially loaded)
    if favorites.itemes.count > 0 && !finishedLoadingInitialTableCells {
        if let indexPathsForVisibleRows = tableView.indexPathsForVisibleRows,
            let lastIndexPath = indexPathsForVisibleRows.last, lastIndexPath.row == indexPath.row {
            lastInitialDisplayableCell = true
        }
    }

    if !finishedLoadingInitialTableCells {

        if lastInitialDisplayableCell {
            finishedLoadingInitialTableCells = true
        }

        //animates the cell as it is being displayed for the first time
        do {
            let startFromHeight = tableView.frame.height
            cell.layer.transform = CATransform3DMakeTranslation(0, startFromHeight, 0)
            let delay = Double(indexPath.row) * 0.2

            UIView.animate(withDuration: 0.7, delay: delay, options: UIViewAnimationOptions.transitionFlipFromBottom, animations: {
                do {
                    cell.layer.transform = CATransform3DIdentity
                }
            }) { (success:Bool) in

            }
        }
    }
}

答案 1 :(得分:1)

在表格源中添加以下代码

public override void WillDisplay(UITableView tableView,
UITableViewCell cell, NSIndexPath indexPath)
    {
            cell.Alpha = 0;

            var transform = CoreAnimation.CATransform3D.MakeTranslation(0, 100, 0);
            cell.Layer.Transform = transform;

            double delay = indexPath.Row * 0.2;

            UIView.Animate(1, delay, UIViewAnimationOptions.TransitionFlipFromBottom,
               () =>
               {
                   cell.Alpha = 1;
                   cell.Layer.Transform = CoreAnimation.CATransform3D.Identity;
               },finished => { }
              );

    }

你可以玩这个值CoreAnimation.CATransform3D.MakeTranslation(x,y,z); X Y Z用于创建转换所需的动画。

double delay = indexPath.Row * 0.2;我为第一次显示de cell时显示稍微延迟的行创建延迟。您可以创建动画而不会延迟添加值0.

enter image description here

cell.Alpha = 0;

这个其他行允许隐藏单元格,当动画开始出现具有淡入淡出效果的单元格时。

UIView.Animate(1, delay, UIViewAnimationOptions.TransitionFlipFromBottom,
               () =>
               {
                cell.Alpha = 1;
               },
                finished => { }
              );

答案 2 :(得分:0)

迅速4:

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    do {
        let startFromHeight = tableView.frame.height
        cell.layer.transform = CATransform3DMakeTranslation(0, startFromHeight, 0)
        let delay = Double(indexPath.row) * 0.2

        UIView.animate(withDuration: 0.7, delay: delay, options: UIViewAnimationOptions.transitionFlipFromBottom, animations: {
            do {
                cell.layer.transform = CATransform3DIdentity
            }
        }) { (success:Bool) in

        }
    }
}