zoukankan      html  css  js  c++  java
  • iOS使用mask切割不规则图案

    起点,终点要闭合:

    CGPathAddQuadCurveToPoint(path, NULL, viewSize.width * 0.5, viewSize.height, viewSize.width, viewSize.height * 0.9); 这个方法画弧线
    /**
     根据几何知识规则 生成不规则图形
     */
    -(void)makeContents3{
        //生成path
        CGMutablePathRef path =CGPathCreateMutable();
        
        CGSize viewSize = self.bounds.size;
        
        CGPathMoveToPoint(path, NULL, 0, viewSize.height * 0.9);//左边直线下点
        
        CGPathAddQuadCurveToPoint(path, NULL, viewSize.width * 0.5, viewSize.height, viewSize.width, viewSize.height * 0.9);
        CGPathAddLineToPoint(path, NULL, viewSize.width, 0);
        CGPathAddLineToPoint(path, NULL, 0, 0);
        CGPathAddLineToPoint(path, NULL, 0, viewSize.height * 0.9); // 形成闭环
        
        
        CAShapeLayer *maskLayer= [CAShapeLayer layer];
        
        //        maskLayer.path=[UIBezierPath bezierPathWithRoundedRect:self.indicateView.bounds cornerRadius:30].CGPath;
        
        maskLayer.path=path;
        
        maskLayer.fillColor=[UIColor blackColor].CGColor;//填充色
        maskLayer.strokeColor=[UIColor redColor].CGColor;
        maskLayer.frame=self.bounds;
        maskLayer.contentsCenter=CGRectMake(0.5, 0.5, 0.1, 0.1);
        //按比例放大 不变形
        maskLayer.contentsScale=[UIScreen mainScreen].scale;
        
        //
        CALayer * contentLayer=[CALayer layer];
        contentLayer.mask=maskLayer;
        contentLayer.frame=self.bounds;
        
        self.layer.mask = maskLayer;
        
    }
  • 相关阅读:
    hdu 2647 Reward
    hdu 2094 产生冠军
    hdu 3342 Legal or Not
    hdu 1285 确定比赛名次
    hdu 3006 The Number of set
    hdu 1429 胜利大逃亡(续)
    UVA 146 ID Codes
    UVA 131 The Psychic Poker Player
    洛谷 P2491消防 解题报告
    洛谷 P2587 [ZJOI2008]泡泡堂 解题报告
  • 原文地址:https://www.cnblogs.com/tufei7/p/10431758.html
Copyright © 2011-2022 走看看