我正在使用(.Fade, .Top, .Bottom e.t.c.)
函数在tableview中插入一系列行。
但是,内置动画样式UITableViewRowAnimation
并不能完全满足我的需求。
我需要创建自己的自定义动画,我知道这可以通过覆盖{{1}}来完成,但我不确定应该如何处理它。
期待您的建议。
欣赏任何见解。
答案 0 :(得分:1)
在UITableView子类中尝试此操作。
override func insertRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation) {
super.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.None)
self.endUpdates()
self.beginUpdates()
for indexPath:NSIndexPath in indexPaths {
let cell:UITableViewCell? = (super.cellForRowAtIndexPath(indexPath))
if cell != nil {
var frame:CGRect = (cell?.frame)!
frame.origin.x = (cell?.frame.size.width)!
cell?.frame = frame
frame.origin.x = 0
let animationBlock = { () -> Void in
cell!.frame = frame;
}
if UIView.respondsToSelector(Selector("animateWithDuration(duration: , delay: , usingSpringWithDamping dampingRatio: , initialSpringVelocity velocity: , options: , animations: , completion: ")) {
// UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options:0.0, animations: animationBlock, completion:nil)
UIView.animateWithDuration(0.3, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: animationBlock, completion: nil)
} else {
UIView.animateWithDuration(0.3, delay: 0.0, options:UIViewAnimationOptions.CurveEaseIn, animations: animationBlock, completion: nil)
}
}
}
}