iOS – Calayer creates transparent round mask

I want to create a mask layer, which is a circle, make the circle content transparent, and keep everything around it. Unfortunately, the code below is just the opposite, it draws a circle And make everything transparent.

CAShapeLayer * shape = [CAShapeLayer layer];
shape.frame = CGRectMake((CGSSize().width/ 2.f)-40.f, -40.f, 80.f, 80.f);

CGPathRef pathRef =
CGPathCreateWithEllipseInRect(CGRectMakeBoundsWithSize(shape.frame.size), NULL );

shape.path = pathRef;
shape.fillColor = [UIColor blueColor].CGColor;

self.layer.mask = shape;
Yes, kCAFillRuleEvenOdd did not do this without first adding rect, here is a working snippet :

CAShapeLayer *shape = [CAShapeLayer layer];

shape.frame = self.bounds;

CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathAddRect(pathRef, NULL, self.bounds);
CGPathAddEllipseInRect(pathRef, NULL, self.bounds);

shape.fillRule = kCAFillRuleEvenOdd;
shape.path = pathRef;

self.layer .mask = shape;

I want to create a mask layer, which is a circle, make the circle content transparent, and keep everything around it. Unfortunately, the following The code is just the opposite, it draws a circle and makes everything transparent.

CAShapeLayer * shape = [CAShapeLayer layer];
shape.frame = CGRectMake((CGSSize().width/2.f)-40.f, -40.f, 80.f, 80.f);

CGPathRef pathRef =
CGPathCreateWithEllipseInRect(CGRectMakeBoundsWithSize (shape.frame.size), NULL);

shape.path = pathRef;
shape.fillColor = [UIColor blueColor].CGColor;

self. layer.mask = shape;

Yes, kCAFillRuleEvenOdd did not do this without first adding rect, here is a working snippet:

CAShapeLayer *shape = [CAShapeLayer layer];

shape.frame = self.bounds;

CGMutablePathRef pathRef = CGPathCreateMutable();
CGPathAddRect(pathRef, NULL, self.bounds);
CGPathAddEllipseInRect(pathRef, NULL, self.bounds);

shape.fillRule = kCAFillRuleEvenOdd;< br />shape.path = pathRef;

self.layer.mask = shape;

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3870 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.