使用 Facebook Pop 对视图仿射变换进行动画处理
Using Facebook Pop to animate view affine transform
我有以下代码,可以以 spring 的方式从底部开始对一些 UITableViewCell
进行动画处理:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tableView.reloadData()
let cellsNum = self.tableView.visibleCells() as NSArray
// Hide the tableView and move the cells to below the tableView
self.tableView.alpha = 0.0
for cell in cellsNum as [UITableViewCell] {
cell.transform = CGAffineTransformMakeTranslation(0, self.tableView.bounds.size.height)
println("\(NSStringFromCGAffineTransform(cell.transform))")
//cell.layer.transform = CATransform3DRotate(CATransform3DIdentity, CGFloat(90.0) * CGFloat(M_PI) / CGFloat(180.0), 1.0, 0.0, 0.0)
}
// Show the tableView and animate the cells
self.tableView.alpha = 1.0
for cell in cellsNum as [UITableViewCell] {
UIView.animateWithDuration(1.2, delay: 0.05 * Double(cellsNum.indexOfObject(cell)), usingSpringWithDamping: 0.77, initialSpringVelocity: 0, options: nil, animations: { () -> Void in
cell.transform = CGAffineTransformMakeTranslation(0, 0)
//cell.layer.transform = CATransform3DRotate(CATransform3DIdentity, 0, 1.0, 0.0, 0.0)
}, completion: nil);
}
}
如何在 Facebook Pop 中执行此操作?我查看了源代码,但最接近的是 kPopLayerTranslationXY,但下面的代码不起作用:
for cell in cellsNum as [UITableViewCell] {
let trans = POPSpringAnimation(propertyNamed: kPOPLayerTranslationXY)
trans.toValue = NSValue(CGPoint: CGPointMake(0, 0))
trans.fromValue = NSValue(CGPoint: CGPointMake(0, self.tableView.bounds.size.height))
trans.springBounciness = 10
trans.springSpeed = 5
cell.pop_addAnimation(trans, forKey: "Translation")
}
可能定义自定义动画属性?
您正在为图层制作动画 属性 因此您应该将动画添加到单元格的图层,而不是单元格。
cell.layer.pop_addAnimation(trans, forKey: "Translation")
此外,由于您只为 y 设置动画,因此您可以使用 kPOPLayerTranslationY
并将 toValue
和 fromValue
设置为浮点数。
我有以下代码,可以以 spring 的方式从底部开始对一些 UITableViewCell
进行动画处理:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.tableView.reloadData()
let cellsNum = self.tableView.visibleCells() as NSArray
// Hide the tableView and move the cells to below the tableView
self.tableView.alpha = 0.0
for cell in cellsNum as [UITableViewCell] {
cell.transform = CGAffineTransformMakeTranslation(0, self.tableView.bounds.size.height)
println("\(NSStringFromCGAffineTransform(cell.transform))")
//cell.layer.transform = CATransform3DRotate(CATransform3DIdentity, CGFloat(90.0) * CGFloat(M_PI) / CGFloat(180.0), 1.0, 0.0, 0.0)
}
// Show the tableView and animate the cells
self.tableView.alpha = 1.0
for cell in cellsNum as [UITableViewCell] {
UIView.animateWithDuration(1.2, delay: 0.05 * Double(cellsNum.indexOfObject(cell)), usingSpringWithDamping: 0.77, initialSpringVelocity: 0, options: nil, animations: { () -> Void in
cell.transform = CGAffineTransformMakeTranslation(0, 0)
//cell.layer.transform = CATransform3DRotate(CATransform3DIdentity, 0, 1.0, 0.0, 0.0)
}, completion: nil);
}
}
如何在 Facebook Pop 中执行此操作?我查看了源代码,但最接近的是 kPopLayerTranslationXY,但下面的代码不起作用:
for cell in cellsNum as [UITableViewCell] {
let trans = POPSpringAnimation(propertyNamed: kPOPLayerTranslationXY)
trans.toValue = NSValue(CGPoint: CGPointMake(0, 0))
trans.fromValue = NSValue(CGPoint: CGPointMake(0, self.tableView.bounds.size.height))
trans.springBounciness = 10
trans.springSpeed = 5
cell.pop_addAnimation(trans, forKey: "Translation")
}
可能定义自定义动画属性?
您正在为图层制作动画 属性 因此您应该将动画添加到单元格的图层,而不是单元格。
cell.layer.pop_addAnimation(trans, forKey: "Translation")
此外,由于您只为 y 设置动画,因此您可以使用 kPOPLayerTranslationY
并将 toValue
和 fromValue
设置为浮点数。