Skip to content

Commit

Permalink
Fixes completion block to fire after all cell animations have complet…
Browse files Browse the repository at this point in the history
…ed, not each individual cell
  • Loading branch information
mergesort committed Aug 28, 2017
1 parent 65d99e9 commit 4587455
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Example/TableFlipExample/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private extension TableViewController {

case .left:
let leftAnimation = TableViewAnimation.Cell.left(duration: 0.5)
self.tableView.animateCells(animation: leftAnimation)
self.tableView.animateCells(animation: leftAnimation, indexPaths: nil, completion: nil)

case .custom:
let degrees = sin(90.0 * CGFloat.pi/180.0)
Expand Down
18 changes: 13 additions & 5 deletions src/UITableView+TableFlip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fileprivate extension UITableView {

fileprivate extension UITableView {

// Fix this one
func animateTableCellsWithDirection(duration: TimeInterval, direction: TableViewAnimation.Cell.AnimationDirection, indexPaths:[IndexPath]?, completion: (() -> Void)? = nil) {

let visibleCells: [UITableViewCell]
Expand All @@ -173,12 +174,16 @@ fileprivate extension UITableView {

UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: 0.0, options: .curveEaseInOut, animations: {
cell.layer.setAffineTransform(.identity)
}, completion: { finished in
completion?()
})
}, completion: nil)
}

let completionDelay: Int = Int((2 * duration)*1000)
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(completionDelay)) {
completion?()
}
}

// Fix this one
func animateTableCellsWithTransform(duration: TimeInterval, transform: CGAffineTransform, options: UIViewAnimationOptions = .curveEaseInOut, completion: (() -> Void)? = nil) {
for (index, cell) in self.visibleCells.enumerated() {
let delay: TimeInterval = duration/Double(self.visibleCells.count)*Double(index)
Expand All @@ -188,9 +193,12 @@ fileprivate extension UITableView {

UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: 0.0, options: options, animations: {
cell.layer.setAffineTransform(.identity)
}, completion: { finished in
}, completion: nil)

let completionDelay: Int = Int((2 * duration)*1000)
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(completionDelay)) {
completion?()
})
}
}
}

Expand Down

0 comments on commit 4587455

Please sign in to comment.