0

In mail.app on the iPhone, a summary of each email is displayed in a UITableView. When the user swipes across a row, the label is resized to accommodate the delete button, and the text is re-wrapped (in a smaller space, the line break can move).

I have figured out how to update the width of the label such that the text re-wraps. But you will also notice that Apple use a neat little fading animation on the label's text as it re-aligns. How can I achieve something similar?

I have attempted to manipulate the alpha for the label in willTransitionToState and didTransitionToState but I can't quite get it to work.

Ben Packard
  • 26,102
  • 25
  • 102
  • 183
  • So you have the size change in an animation block? Its not an alpha thing because only the text that is moving does the crossfade. EDIT: to clarify, I mean not a manipulation of the alpha on the whole label. – Matt Oct 17 '12 at 22:07
  • They might be doing a check to see if the text will be re-wrapped or not. – Ben Packard Oct 17 '12 at 22:17

1 Answers1

1

I checked iOS 5 behavior to make sure it wasn't enabled by the added support for NSAttributedString in iOS 6, and it doesn't seem to be. Since thats the case, I see a couple ways of recreating it. I have done something similar but not this exactly, so take this with a grain of salt (but I'm almost positive it will have the exact same effect).

You can try the following...

Add a mask layer to the UILabel. The mask layer should let everything through. (So blackColor will work as the background color I believe). Add a sublayer to the mask layer. This sublayer will be the driver for the effect. It will fade its background color from black to white (making what's underneath it fade out). You want the sublayer mask to apply to the area of the label that is disappearing. You can just fix the frame to this area and it should work out. Let me know if you need some sample code.

EDIT:

Have you seen this thread? That might help make it work implicitly. animate textlabel in uitableviewcell using willTransitionToState

Community
  • 1
  • 1
Matt
  • 1,586
  • 8
  • 12