贝塞尔曲线绘制人脸框(框内全透明,框外半透明)

参考CropImage 制作截取头像框https://github.com/cokeduo/CropImage
//www.greatytc.com/p/c883fbf52681

//贝塞尔曲线画4个弧度
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, kScreenWidth, kScreenHeight) cornerRadius:0];
    UIBezierPath *headerPath = [UIBezierPath bezierPath];
    headerPath.lineWidth = 2.0;
    headerPath.lineCapStyle = kCGLineCapRound;
    headerPath.lineJoinStyle = kCGLineJoinRound;
    [headerPath moveToPoint:CGPointMake(kScreenWidth/2, 80+STATUS_BAR_Y)];
    [headerPath addQuadCurveToPoint:CGPointMake(kScreenWidth*(1-0.75)/2+kScreenWidth*0.75, 80+STATUS_BAR_Y+kScreenWidth*0.35) controlPoint:CGPointMake(kScreenWidth*(1-0.75)/2+kScreenWidth*0.75, 80+STATUS_BAR_Y)];
    [headerPath addQuadCurveToPoint:CGPointMake(kScreenWidth/2, 80+STATUS_BAR_Y+kScreenWidth) controlPoint:CGPointMake(kScreenWidth*(1-0.75)/2+kScreenWidth*0.75, 80+STATUS_BAR_Y+kScreenWidth)];
    [headerPath addQuadCurveToPoint:CGPointMake(kScreenWidth*(1-0.75)/2, 80+STATUS_BAR_Y+kScreenWidth*0.35) controlPoint:CGPointMake(kScreenWidth*(1-0.75)/2, 80+STATUS_BAR_Y+kScreenWidth)];
    [headerPath addQuadCurveToPoint:CGPointMake(kScreenWidth/2, 80+STATUS_BAR_Y) controlPoint:CGPointMake(kScreenWidth*(1-0.75)/2, 80+STATUS_BAR_Y)];
    [headerPath stroke];
    [path appendPath:headerPath];
    [path setUsesEvenOddFillRule:YES];
    CAShapeLayer *fillLayer = [CAShapeLayer layer];
    fillLayer.path = path.CGPath;
    //中间透明
    fillLayer.fillRule = kCAFillRuleEvenOdd;
    //半透明效果
    fillLayer.fillColor = [UIColor colorWithHexString:@"0x000000" alpha:0.4].CGColor;
    [self.layer addSublayer:fillLayer];
    //绘制虚线边框
    CAShapeLayer *vertulLineLayer = [CAShapeLayer layer];
    vertulLineLayer.path = headerPath.CGPath;
    vertulLineLayer.strokeColor = [UIColor whiteColor].CGColor;
    vertulLineLayer.fillColor = [UIColor clearColor].CGColor;
    vertulLineLayer.lineCap = kCALineCapRound;
    vertulLineLayer.lineWidth = 2;
    vertulLineLayer.lineDashPattern = @[@8,@8];
    [self.layer addSublayer:vertulLineLayer];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 偶然发现,用过一些,分享给大家 { "XcodeChaJian": [ { "Dname":"...
    MonkeyHan阅读 6,622评论 0 4
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,420评论 25 708
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 12,960评论 2 59
  • 初夏的早晨, 在河畔边漫步徜徉 与爱人手拉着手 温馨点点 一簇簇枝叶随风起舞 在光波中垂下珠帘 叶子玲珑娇媚 莎莎...
    A小天鹅阅读 195评论 0 1
  • 有一个笑容,一辈子无法忘怀! 70年代,铁岭大青腰堡。 那是一个物质匮乏的年代,还没有计划生育的年代。那段记忆,最...
    黄玫瑰有约阅读 257评论 0 1