4

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?

Community
  • 1
  • 1
prime31
  • 171
  • 2
  • 9
  • How are you drawing your Cells? If you're following Loren's advice, you should be directly drawing them vs a bunch of subviews. Do you have subviews (such as `UILabel`) or are you drawing things directly (like `[myString drawInRect:someRect]`)? – jbrennan Sep 07 '09 at 03:27

1 Answers1

1

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
  • 4,962
  • 1
  • 23
  • 27
  • 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. – prime31 Sep 09 '09 at 15:10