Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Masking" an animation? iPhone SDK

I have been looking into ways of masking images on the iPhone. I came across this solution

http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

which works great for still images. What I want to do is mask an animation in a UIImageView. From what I have read I don't think this is possible whilst also achieving a decent frame rate.

This leads me to ask whether the following is possible, could I "clip" the images inside the UIImageView? ie not re-size the UIImageView to the size of the images so some parts are chopped off?

like image 695
user157733 Avatar asked Dec 14 '22 01:12

user157733


1 Answers

I haven't tried this for performance, but you can use a Core Animation layer as a mask. You can define a path to use in a CAShapeLayer and fill the shape. Then specify the layer mask of your UIImageView's layer. Something like:

CGMutablePathRef path = CGPathCreateMutable();
// build the path by adding points
// ...

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
[shapeLayer setPath:path];
[shapeLayer setFillColor:[[UIColor blackColor] CGColor]];
// Set shape layer bounds and position
// ...

// Set the mask for the image view's layer
[[imageView layer] setMask:shapeLayer];

Keep in mind that this isn't actually creating a new image as the link you reference does. This just creates a mask for display over top of your image view--which may not be what you want.

like image 64
Matt Long Avatar answered Dec 28 '22 01:12

Matt Long