The challenge for Chapter 21 involves fixing the issue where the widget view “snaps” to an initial position if the user taps the “show more / less” button a second time for the first animation has finished. However, the ‘solution’ to the challenge provided with the PDF does not actually address this issue, as the view still has a jerk to the final position of the first animation before beginning the animation back to the original state. I haven’t actually been able to find a proper solution to the issue, but I’ll update here if I fix it tonight or tomorrow.
I believe the error in this challenge is relying on the tableview begin updates and end updates methods to animate the cell height change. When animating a standard view constraints, changing the constant value in subsequent animation blocks does result in a nice, smooth animation. However, when changing the tableview row height, when you tap the button to initiate the change before the previous row height change animation has finished, the previous animation snaps to it’s final position.
Even more baffling though, is that any interaction with the the widgetCell (either tapping one of the icons, or tapping another button I created that doesn’t relate to the animations at all) causes the widget view to snap to the final position of the most recently induced animation.
Basically there is a lot of strange behavior going on in large part due to relying on the beginUpdates and endUpdates to animate the change and manage the state of the tableview. I’d be interested if anyone else has come up with a good solution to this issue.