Skip to content

Commit 4587455

Browse files
committed
Fixes completion block to fire after all cell animations have completed, not each individual cell
1 parent 65d99e9 commit 4587455

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Example/TableFlipExample/TableViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private extension TableViewController {
116116

117117
case .left:
118118
let leftAnimation = TableViewAnimation.Cell.left(duration: 0.5)
119-
self.tableView.animateCells(animation: leftAnimation)
119+
self.tableView.animateCells(animation: leftAnimation, indexPaths: nil, completion: nil)
120120

121121
case .custom:
122122
let degrees = sin(90.0 * CGFloat.pi/180.0)

src/UITableView+TableFlip.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fileprivate extension UITableView {
153153

154154
fileprivate extension UITableView {
155155

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

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

174175
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: 0.0, options: .curveEaseInOut, animations: {
175176
cell.layer.setAffineTransform(.identity)
176-
}, completion: { finished in
177-
completion?()
178-
})
177+
}, completion: nil)
178+
}
179+
180+
let completionDelay: Int = Int((2 * duration)*1000)
181+
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(completionDelay)) {
182+
completion?()
179183
}
180184
}
181185

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

189194
UIView.animate(withDuration: duration, delay: delay, usingSpringWithDamping: damping, initialSpringVelocity: 0.0, options: options, animations: {
190195
cell.layer.setAffineTransform(.identity)
191-
}, completion: { finished in
196+
}, completion: nil)
197+
198+
let completionDelay: Int = Int((2 * duration)*1000)
199+
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(completionDelay)) {
192200
completion?()
193-
})
201+
}
194202
}
195203
}
196204

0 commit comments

Comments
 (0)