Last active
February 12, 2017 16:56
-
-
Save newmarcel/e7206848efd84aa7f2b7 to your computer and use it in GitHub Desktop.
UITableView+CATransaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITableView+CATransaction.swift | |
// | |
// Created by Marcel Dierkes on 08.05.15. | |
// Copyright (c) 2015 Marcel Dierkes. All rights reserved. | |
// | |
import UIKit | |
import QuartzCore | |
public extension UITableView { | |
/** | |
Animates multiple insert, delete, reload, and move operations as a group. | |
Source: http://stackoverflow.com/a/12516056 | |
- parameter updates: The block that performs the relevant insert, delete, reload, or move operations. | |
- parameter completion: A completion handler block to execute when all of the operations are finished. This block takes a single Boolean parameter that contains the value `YES` if all of the related animations completed successfully or `NO` if they were interrupted. This parameter may be `nil`. | |
*/ | |
func performBatchUpdates(updates: (() -> Void)?, completion: ((finished: Bool) -> Void)?) { | |
CATransaction.begin() | |
CATransaction.setCompletionBlock { | |
completion?(finished: true) | |
} | |
self.beginUpdates() | |
updates?() | |
self.endUpdates() | |
CATransaction.commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment