Ben Packard
Ben Packard

Reputation: 26476

Knowing when a modal animation is complete

I allow users to add new items using a modal, presented vertically. When they are done, the modal slides out of view and the new item is added to the list.

I want the user to see the impact of his addition by inserting the new row with animation, (or maybe selecting it). The trouble is, if the cell is at the bottom of the list, the user doesn't really get to see the animation, as it happens under the still-disappearing modal.

Is there a way to know when this animation is complete? Or do I need to do something more crafty/hacky*

* I am thinking of storing a reference of the added cell in an iVar and then inserting it in viewDidAppear, which does not fire until after the modal has completed it's transition - other ideas would be appreciated.

EDIT: My second hacky idea is to wrap the modal dismissal in an animation block of equal duration (0.3?) to the dismissal.

Upvotes: 0

Views: 336

Answers (2)

RileyE
RileyE

Reputation: 11084

If, by some odd circumstance, the completion block doesn't float your boat, the current default animation time for most apple animations is 0.25f seconds. You can hard code a delay and perform an action after that, but its not recommended. Its just a work around. You should do what Robert and Ben said when you can.

Upvotes: 1

Rob
Rob

Reputation: 437632

How are you doing your modal transition? If you use presentViewController instead of presentModalViewController, you have a completion block. Likewise, the dismissViewControllerAnimated also has a completion block (where as the old dismissModalViewControllerAnimated does not). These were introduced in iOS 5.

Upvotes: 1

Related Questions