Masking animations? iPhone SDK

I was looking for ways to mask 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. I want to make an animation mask in a UIImageView. From what I read, I don’t think it’s possible, at the same time achieving a decent frame rate.

This allows me to ask if the following is possible: is it possible to β€œpin” images inside a UIImageView? those. Don't resize UIImageView to image size so some parts are chopped off?

+4
source share
2 answers

I have not tried this for performance, but you can use the Core Animation layer as a mask. You can determine the path to use in CAShapeLayer and fill out the form. Then specify the layer mask of your UIImageView layer. Sort of:

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 layer [[imageView layer] setMask:shapeLayer]; 

Keep in mind that this does not actually create a new image, like the link you are linking to. It just creates a mask to display on top of your image - it may not be the way you want.

+8
source

I searched high and low and finally found a solution with almost no limits. So here you are:

 UIImageView *maskeeImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MaskeeImage.png"]]; [maskeeImage setAnimationRepeatCount:-1]; [maskeeImage setAnimationImages:[[NSArray alloc] initWithObjects:[UIImage imageNamed:@"MaskeeImage1.png"], [UIImage imageNamed:@"MaskeeImage2.png"], [UIImage imageNamed:@"MaskeeImage3.png"], nil]]; [maskeeImage startAnimating]; CALayer *maskeeLayer = [maskeeImage layer]; maskeeLayer = CGRectMake(0, 0, 768, 1004); [[[self view] layer] addSublayer:maskeeLayer]; UIImage *maskImage = [UIImage imageNamed:@"ImageMask.png"]; CALayer *maskLayer = [CALayer layer]; maskLayer.contents = (id) myImageMask.CGImage; maskLayer.frame = CGRectMake(0, 0, 768, 1004); [maskeeLayer setMask:maskLayer]; 

Come here! It is really very simple as soon as you know how to do it. I tried to show a few different options; Using UIImageViews or UIImages, Animations (which can also be used for masks).

To summarize all this, you basically need to set the mask property to your CALayer. Each subclass of UIView has a CALayer attached to it, so you are not limited at all to where you get your mask or disguise from.

Hope this helps. Hi Dylan

+5
source

All Articles