[英]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.