简体   繁体   English

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

[英]How to animate a UITableViewCell transition from bottom to the top in Xamarin iOS?

How to animate a UITableViewCell transition from bottom to the top in Xamarin iOS native? 如何在Xamarin iOS本机中为从底部到顶部的UITableViewCell过渡设置动画?

Hi all community of Xamarin iOS native, I'm searching a way to animate a UITableViewCell in a UITableView, create a transition from bottom to the top with a fade effect for any cell. 大家好,我是Xamarin iOS本机的所有社区,我正在寻找一种在UITableView中对UITableViewCell进行动画处理的方法,创建从底部到顶部的过渡,并为任何单元格提供淡入淡出效果。

在此处输入图片说明

Because all the examples that I find are in Swift, I solve this answer for my own I will share the solution for the community. 因为我找到的所有示例都在Swift中,所以我自己解决了这个问题,我将为社区分享解决方案。

in the table source add the fallowing code 在表格源中添加休闲代码

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 => { }
              );

    }

you can play with this values CoreAnimation.CATransform3D.MakeTranslation(x, y, z); 您可以使用此值CoreAnimation.CATransform3D.MakeTranslation(x,y,z); XYZ to create the animation that you want with the transition. XYZ以创建所需的过渡动画。


double delay = indexPath.Row * 0.2; 双延迟= indexPath.Row * 0.2; I create a delay for the rows that show a little delay when show de cell for the first time. 我为第一次显示de cell的行创建了一个延迟。 you can create your animation without the delay adding a value of 0. 您可以创建动画而不会延迟添加0值。

在此处输入图片说明

cell.Alpha = 0;

this other line permit hide the cell and when the animation start the cell appearing with a fade effect. 另一行允许隐藏单元格,当动画开始时,该单元格以淡入淡出效果出现。

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

Swift 4 and fix scroll issue: Swift 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

            }
        }
    }
}

Swift 4: 斯威夫特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

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 xamarin forms 的初始屏幕中设置动画或从底部到顶部的过渡? - Animate or do a transition from bottom to top in splash screen in xamarin forms? 如何使 ViewController 从底部过渡到顶部? - How to make transition of a ViewController from Bottom to Top? 如何使用CATransform3D在iOS中从底部到顶部对视图进行动画处理 - how to animate view from bottom to top in iOS using CATransform3D 如何在iOS中从TableView高度的底部到顶部插入动画的TableView行 - How to insert tableview row animate from bottom of tableview height to top in ios 如何在目标c中从上至下选择UITableViewCell? - How to select the UITableViewCell from top to bottom in objective c? 如何从上到下为视图设置动画并正确堆叠该视图? - How to animate a view from top to bottom and stacking that view properly? 如何在swift4中为图库从底部到顶部设置动画 - How to animate a view from bottom to top for gallery in swift4 如何使用约束从下到上为UIView设置动画? - How to animate UIView using constraint from bottom to top? 如何在 Swift 1.2 中从下到上动画 UIlabel - How to animate UIlabel from bottom to top in Swift 1.2 如何在导航控制器中从下至上更改过渡动画? - How to change the transition animation from bottom to top in navigation controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM