Wayne Filkins Wayne Filkins - 1 year ago 96
Swift Question

Move a button from one UITableViewCell to another with animation in Swift

I have a button and I want to keep track of which cell has the button with firebase. I can do this by putting the button in all cells and just make it visible in the one cell using firebase data. The part I'm stuck on is animating the button to move from one cell to another.

The only way I can think of is to put a delay on moving it from one to another, then have a separate animation happen. Then I think if I make the delay the same as the animation's duration then it will look like it just moved. I just thought of that while typing this but let me know if there's an easier/better way please!

Answer Source

This is a pretty tough thing to do, and animations can sometimes be one of the most difficult parts of mobile development. You aren't super clear on what your animation should look like, but since UITableViewCells each have their own contentViews I don't think directly animating the button from one cell to another is possible.

The best method I could think is to:

1) Draw a button on the screen at the location of the button you want to move

2) Hide the real button underneath

3) Animate this fake button over the tableview to the spot of the new, real button

4) End the animation and show the real button.

But you might have to block user interaction with the tableview while this happens to prevent them from scrolling and screwing up the animation...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download