Search code examples
iosanimationuibuttonfading

Animation of UIButtons in ScrollView


I render "n" UIButtons into a ScrollView. I've subclassed the UIButton to handle long taps.

The UIButtons are of type "custom" and display only a 150px x 150 PC image from Documents Directory.

If the user taps longer on one of the UIButtons a red cross comes up on the upper right corner to allow him to delete the selected UIButton from view.

And here is my problem:

I need to animate the deletion a bit. What I want is to fade out the selected UIButton and move the UIbuttons on the right of the deleted UIbutton one position to the left (animated).

I worked through several animation tutorials on the web, but i don't know how to fade in/out a UIButton or animate them in this scenario.


Solution

  • Just an example of how to fade out a control:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration: 0.3];
    
    [yourButton setAlpha:.0];
    
    [UIView commitAnimations];
    

    Change the frame of the other buttons to the new location before commiting the animation. Hope it helps.