ios – CALayer创建透明圆形面具

ios – CALayer创建透明圆形面具,第1张

概述我想创建一个遮罩层,这是一个圆圈,使圆圈内容透明,并保持周围的一切.不幸的是,下面的代码恰恰相反,它绘制了一个圆圈并使一切变得透明. CAShapeLayer * shape = [CAShapeLayer layer];shape.frame = CGRectMake((CGSSize().width/2.f)-40.f, -40.f, 80.f, 80.f);CGPat 我想创建一个遮罩层,这是一个圆圈,使圆圈内容透明,并保持周围的一切.不幸的是,下面的代码恰恰相反,它绘制了一个圆圈并使一切变得透明.

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;
解决方法 是的,kCAFillRuleEvenOdd在没有首先添加rect的情况下没有做到这一点,这里有一个工作片段:

CAShapeLayer *shape = [CAShapeLayer layer];shape.frame = self.bounds;CGMutablePathref pathref = CGPathCreateMutable();CGPathAddRect(pathref,NulL,self.bounds);CGPathAddEllipseInRect(pathref,self.bounds);shape.fillRule = kCAFillRuleEvenOdd;shape.path = pathref;self.layer.mask = shape;
总结

以上是内存溢出为你收集整理的ios – CALayer创建透明圆形面具全部内容,希望文章能够帮你解决ios – CALayer创建透明圆形面具所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1008490.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存