Right now I am making an iPad app that involves a UITableView
that involves UITableView Cells
that slide left and right, I have a NSNotification
based system of letting the UITableViewController
know when a slide occurs. I need to display a UITableViewCell
under the cell that was moved and above the cell that was below the moved cell. I would like to do a fold animation as seen in the app clear but without the pinch gesture
(i.e. automated fold). I have found this library called MPFoldTransition. However, it doesn't support UITableView
. I have also looked into the pinch gesture
in this tutorial, however this tutorial doesn't tell me how to automatically animate the animation, as it requires the users to do a pinch gesture. I have looked around the web and cant seem to find anything. I will appreciate any help whatsoever.
Thanks
This is completely possible using MPFoldTransition
's transitionFromView: toView:...
. I've created a sample project that I can link to if you'd like, but it all really boils down to this:
- (void)addNewTableCellToIndexPath:(NSIndexPath *)indexPath {
// Add the new object to the datasource and reload the row
[dataSourceArray insertObject:@"New" atIndex:indexPath.row];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
//setup temporary cell
UITableViewCell *fromCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
[fromCell setBackgroundColor:[[self.tableView cellForRowAtIndexPath:indexPath] backgroundColor]];
//setup cell to animate to
UITableViewCell *toCell = [self.tableView cellForRowAtIndexPath:indexPath];
[toCell.textLabel setText:dataSourceArray[indexPath.row]];
//add fold animation to the cells create above
[MPFoldTransition transitionFromView:fromCell
toView:toCell
duration:0.4
style:MPFoldStyleUnfold
transitionAction:MPTransitionActionNone
completion:^(BOOL finished) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}];
}
About is a function that takes the index path as an argument. Send it the index path that you wish to add the cell with a fold transition, and it will create a blank temporary cell on the table to fold from, while shifting the rest of the cells down. It isn't perfect, mostly because I haven't figured out a way to change UITableViewRowAnimation
's duration to perfectly match up with the folds duration.
Either way, this should be enough to get you going. Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With