Updating the Frame of a UITableView in iOS 10

In Shopster, when you edit an element in the main UITableView, we show a “ruler” to allow for selecting the item quantity. When the ruler is shown, we make the table view narrower, so the text is still visible to the user.

In iOS 10, however, Apple slightly changed the behaviour of UITableView, and the animation started failing as follows:

In the animation closure, we are simply changing the UITableView’s frame. As you can see on the video, this makes the animation “jump”. The disclosure arrows move before the animation even start.

The solution, luckily, is simple: just wrap the frame update in a beginUpdates / endUpdates pair as follows:

// assumes currentFrame is set previously.
self.tableView.frame = currentFrame

If you want to play around with the example, here’s an interactive playground you can download to reproduce the issue or see the workaround.