Search code examples
xcodeuibuttoncaanimation

CAAnimation on a UIButton


I have been trying to create a simple swipe transition. However buttons seem immune to any CAAnimation that crops.

I am trying to get it so that a bar moves across the screen and as it goes over the button it removes the part it has just gone over.

I have tried bounds.width, size.x and many other key-value paths to achieve the affect but I haven't got what I wanted. It just relocates the text which always remains entirely visible I have also tried changing the UIButton to a UIImage but the text does not seem to print on a UIImage. I tried using masks too but I have heard they should be used as infrequently as possible as they consume the phones resources. I didn't really get very far with this either anyway as I hadn't used them much before. I also tried placing it in a container view and then change the dimensions of that but again all of the text remained entirely visible.

I know I could have a view hide the button but I am trying to reveal the view behind as the bar swipes.

Does anyone have any suggestions of how to achieve a swipe transition on a UIButton?

Help would be much appreciated.

Thanks


Solution

  • I think what you're looking for really is a mask. See the tutorial here: http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

    What I'd do in your situation is create a custom UIButton class, and add a mask as in the tutorial, then animate the position of the mask. Slide the mask of, nothing shows. Slide it on, part shows until the whole thing is visible.

    Edit: I haven't really heard anything about hogging resources, especially since it appears to be simple core graphics.