3

I am looking to perform one of two things; slow down or alter the default animation duration for inserting rows into a UITableView or stagger the insertion of the UITableView cells so it gives the illusion that animation has slowed down. So far I have not been unsuccessful.

I have reviewed a couple of related threads so far without any success in iOS 10, Swift 3:

Change duration of UITableView animation (Insert/Delete rows with table beginUpdates)

UITableView row animation duration and completion callback

Can you do custom animations for UITableView Cell Inserts?

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html

One routine that I tried but was unsuccessful at was staggering an array of rows (indexPaths) to be input on a one second interval to give the illusion that the animation duration was slowing. From a conceptual standpoint, this seems like it should work. However, on the first iteration when endUpdates() is called an NSException crash occurs.

func insertNewRows() {
   // perform new data source input here
   // gather an array of index paths that will need to be inserted here
   // setup index counter here to coordinate which index path we are at
   // setup a one second timer to hit a callback that inserts one of the index paths at a time here
}

func insertOneRow() {
   // check to see if we reached the end of the index paths array and if so invalidate timer
   // if we have not reached the end of the index paths array perform the following code snippet below
   customTableView.beginUpdates()
   customTableView.insertRows(at: [indexPath], with: .bottom)
   customTableView.endUpdates()
   // The endUpdates call crashes the execution with an NSException
}

One other idea that I tried but was unsuccessful with was to add all of the indexPaths into the UITableView with no animation, hide all the rows/cells and fade them in one by one. This idea was based off of this answer: Can you do custom animations for UITableView Cell Inserts? The issue with the following idea above is that I could never hide the tableview cells and they all would come in at once and the animation would take place after the cells are present in the UITableView.

One other idea I had was to work with tableView(_:willDisplay:forRowAt:). https://developer.apple.com/reference/uikit/uitableviewdelegate/1614883-tableview However, I ran into another set of issues where rows/cells did not pass through this function in order and I could not control the animation accurately and most of the rows/cells would show up visible before I could hide them and animate them.

So, this leaves me wondering, what are the options for performing a insertRows duration alteration?

  • Possibly is there a way to successfully do this with a custom UITableViewRowAnimation that I am not aware of?
  • Is there a way to hook into UIKit > UITableView and control the duration that I am not aware of?
  • Is this just not available and is this just not available for a reason?

These are some of the questions that I have been left wondering and thought I would put this out there in case anyone else has run into this or came up with a recent iOS 10 solution to this.

Community
  • 1
  • 1
AgnosticDev
  • 1,843
  • 2
  • 20
  • 36

0 Answers0