simonbs
simonbs

Reputation: 8042

UITableViewCell animation while scrolling

I have a UITableView with custom UITableViewCells in it. These cells can be opened and closed with an animation. When the user scrolls I would like to close the cell. I do this by posting a notification like this:

[[NSNotificationCenter defaultCenter] postNotificationName:@"closeSwipedCell" object:nil];

This will call a method which does my simple animation in my subclass of UITableViewCell. This is working fine but the animation won't happen until the user stops scrolling the UITableView again. Is it possible to do this animation while scrolling the table view?

Upvotes: 2

Views: 2665

Answers (3)

kris
kris

Reputation: 2526

Here's a great detailed explanation of how to do a swipe to a cell submenu, like the twitter iphone app. I think it's very similar to what your looking for. It doesn't use notifications to close a cell, it uses the events from the UIScrollViewDelegate as the other commenters have recommended.

iDevRecipes look for the post on idevrecipes.com called "How does the Twitter iPhone app implement side swiping on a table".

There's good description but also code to download.

Upvotes: 2

Ben Mosher
Ben Mosher

Reputation: 13381

scrollViewDidScroll: may only be called at the end of the user scrolling. You may want to try firing your notification using the scrollViewWillBeginDragging: delegate method, which will definitely be called at the beginning of the scroll action.

There are also several UIViewAnimationOptions constants (IIRC, UIViewAnimationOptionBeginFromCurrentState is the one I'm thinking of) that affect whether animation will begin during another animation action, such as scrolling (tracking).

You'll need to OR that option with your existing animation options in the options: parameter of your animation method call.

Upvotes: 0

Kristofer Sommestad
Kristofer Sommestad

Reputation: 3061

You should be able to listen to the UIScrollViewDelegate method scrollViewDidScroll: and fire your event then.

Check out the Apple docs on UIScrollViewDelegate.

EDIT: If I was unclear, the UITableViewDelegate conforms to the UISCrollViewDelegate.

Upvotes: 0

Related Questions