views:

910

answers:

1

I am trying to do something very similar to this post. Starting with Atebits Fast Scrolling in Tweetie post I have a UITableView subclass that does all of it's drawing in the drawRect: method of it's contentView. This works perfectly and is super fast. What I am trying to do now is animate the transition from editing to not-editing.

An example of what I am trying to achieve would be a situation with some text right aligned in the cell. When entering edit mode, the contentView shifts right to allow room for the editing control but the text shifts offscreen on the right as well. If I simply call [contentView setNeedsDisplay] in layoutSubviews I can readjust the right aligned text but it just jumps to it's new position.

How can I get the transition to animate?

+1  A: 

Your layoutSubviews should look like this:

-(void)layoutSubviews {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:YES];

    /* Change offsets here. */

    [UIView commitAnimations];
}

You may also need to add to applicationDidFinishLaunching:

[UIView setAnimationsEnabled:YES];
John Franklin
layoutSubviews implicitly does animation for you so the beginAnimations/commitAnimations isn't required. This doesnt work when you are drawing your own content in drawRect: because there are no offsets to change. Animations only work when using UIView subclasses.
uprise