0

I have a tableview that has expandable cells. When you click on a cell a date picker shows inline. When you click on another, a different kind of picker shows. I have set it up so when you click on any cell, any open cells will close, so as to ensure that only one cell is open at a time.

My problem is: the animations for a) the first cell closing, and b) the second cell opening are overlapping, which doesn't look great at all.

When I click a cell I would like the expanded cell to close, and THEN the second cell to expand, with enough of a delay so the animations don't overlap.

I have looked for a Swift solution online but haven't been able to find an answer. I am fairly new to iOS dev, so don't know much about UIAnimation, etc.

Using Xcode 7.2, Swift.

Any help would be appreciated.

thecloud_of_unknowing
  • 1,103
  • 14
  • 23

1 Answers1

0

You can try to use the completion for that.

UIView.animateWithDuration(0.5, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { 
    //your first animation
}, completion: {(finished:Bool) in
    //your seconde animation (or whatever you want to be done when the first one is completed)
})

OR

You can use a CATransaction, see : Wait for Swift animation to complete before executing code

OR

You can try to force them to run on the same thread instead of using parallel threads ?

For example, here is how you can force an action to be done on the main thread :

dispatch_async(dispatch_get_main_queue()) {
    //your animation
}

There may also be some other solutions, good luck

Community
  • 1
  • 1
vbuzze
  • 930
  • 1
  • 11
  • 25
  • In the end I needed to use CATransaction. I couldn't use animationWithDuration and a completion because placing the code that closes the first cell (removeCellAtIndexPath) in the animationWithDuration caused some weird things to happen with the TableView animations. In fact, neither insertRowsAtIndexPath or removeRowsAtIndexPath take kindly to being placed in animationWithDuration. But when I used CATransaction, placing the second animation in the completion block, it worked nicely. Thanks to @BUZZE for the answer. – thecloud_of_unknowing Mar 12 '16 at 10:03