使用UIBezierPath贝塞尔曲线配合CAShapeLayer抠图
2019独角兽企业重金招聘Python工程师标准>>>
##使用UIBezierPath贝塞尔曲线配合CAShapeLayer抠图
###系统提供的UIBezierPath构造方法
先来看看构造方法列表,以及构造出来的形状,具体详见后面的示例及图片。
1、矩形
+ (instancetype)bezierPathWithRect:(CGRect)rect;
2、内切圆,即椭圆
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
3、圆角矩形
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius; // rounds all corners with the same horizontal and vertical radius
,可设置圆角的半径
4、部分圆角的矩形
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
* rect: 矩形frame
* corners: 要画成圆角的部位
* cornerRadii: 圆角的大小
5、圆弧
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
* center: 圆心坐标
* radius: 圆的半径
* startAngle: 起点角度
* endAngle: 终点角度
* clockwise: 是否顺时针
6、指定路径
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;
###配合CAShapeLayer
利用CAShapeLayer,能画出各种形状,只需要将UIBezierPath的CGPath赋予CAShapeLayer的path即可。
####代码示例
// 要抠的透明区域位置
CGRect cutFrame = CGRectMake(0, 200, self.view.bounds.size.width, 400);
UIBezierPath *cutPath1 = [UIBezierPath bezierPathWithRect:cutFrame];//图1 - 普通矩形
/*UIBezierPath *cutPath2 = [UIBezierPath bezierPathWithRoundedRect:cutFrame cornerRadius:20];//图2 - 圆角为20的圆角矩形UIBezierPath *cutPath3 = [UIBezierPath bezierPathWithRoundedRect:cutFrame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];//图3 - 左上和右上为圆角20的部分圆角矩形UIBezierPath *cutPath4 = [UIBezierPath bezierPathWithOvalInRect:cutFrame];//图4 - 内切圆(椭圆)*/// 要抠透明区域的原图
CGRect viewFrame = self.view.bounds;
UIBezierPath *viewPath = [UIBezierPath bezierPathWithRect:viewFrame];// 调用bezierPathByReversingPath,进行路径反转,才会产生抠图效果
[viewPath appendPath:[cutPath1 bezierPathByReversingPath]];// 配合CAShapeLayer,调用layer(此layer必须是第一层,不能嵌套)的setMask方法设置遮罩层
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = viewPath.CGPath;
[self.view.layer setMask:shapeLayer];
####效果图
#####图1 - 普通矩形
#####图2 - 圆角为20的圆角矩形
#####图3 - 左上和右上为圆角20的部分圆角矩形
#####图4 - 内切圆(椭圆)
转载于:https://my.oschina.net/u/3729372/blog/1591239
使用UIBezierPath贝塞尔曲线配合CAShapeLayer抠图相关推荐
- 贝塞尔曲线与CAShapeLayer的关系以及Stroke动画
1.贝塞尔曲线与CAShapeLayer的关系 1.1CAShapeLayer须要一个形状才干生效,贝塞尔曲线能够创建基于矢量的路径.进而能够给CAShapeLayer提供路径,路径会闭环. ...
- 通过UIBezierPath贝塞尔曲线画圆形、椭圆、矩形
/**创建椭圆形的贝塞尔曲线*/UIBezierPath *_ovalPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, ...
- iOS开发 贝塞尔曲线UIBezierPath(后记)
使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...
- 基于CAShapeLayer和贝塞尔曲线的圆形进度条动画
通过CAShapeLayer和贝塞尔曲线搭配的方法,创建的简单的圆形进度条的教程 先简单的介绍下CAShapeLayer 1,CAShapeLayer继承自CALayer,可使用CALayer的所有属 ...
- ios 贝塞尔曲线 颜色填充_iOS贝塞尔曲线(UIBezierPath)的基本使用方法
简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...
- 贝塞尔曲线UIBezierPath简单使用
//常用属性 /* 1.CGPath: 将UIBezierPath类转换成CGPath 2.currentPoint: 当前path的位置,可以理解为path的终点 3.lineWidth: 线条宽度 ...
- ios 贝塞尔曲线 颜色填充_iOS,贝塞尔曲线(UIBezierPath)
UIBezierPath简介 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装, UIBezierPath对象是C ...
- ios 贝塞尔曲线 颜色填充_IOS 贝塞尔曲线(UIBezierPath)属性、方法整理
IOS 贝塞尔曲线详解 开发IOS的朋友都知道IOS 贝塞尔曲线的重要性,由于经常会用到这样的东西,索性抽时间就把相应所有的属性,方法做一个总结. UIBezierPath主要用来绘制矢量图形,它是基 ...
- iOS开发 贝塞尔曲线UIBezierPath
2019独角兽企业重金招聘Python工程师标准>>> UIBezierPath基础 UIBezierPath对象是CGPathRef数据类型的封装.每一个直线段或者曲线段的结束的地 ...
最新文章
- Linux中的输入输出管理
- 《滚动数组》---滚动数组思想,运用在动态规划当中
- 火狐已阻止载入混合活动内容“http://www.XXX/index.php?app=serviceac=authts=isauthurl=...
- 转账示例(二):service层面实现(本例采用QueryRunner来执行sql语句,数据源为C3P0)...
- error: conversion from ‘const char [ ]‘ to non-scalar type
- jpg无损压缩 java_使用FreeImage对JPEG进行无损优化
- 如何在C#中使用反射获取集合元素类型
- 【杂谈】excel列表创建后,怎么删除蓝色边框线?
- 使用Redis存取数据+数据库存取(spring+java)
- 普林斯顿微积分读本篇十七:数列和级数,泰勒定理
- fckeditor java_FCKeditor.Java 源代码下载
- 峰值性噪比matlab,PSNR峰值信噪比matlab实现
- bootstrap的提示框bootbox.js
- PHP, 将 PDF/Word/PPT 文档转换成图片生成长图
- RTI_DDS自定义插件开发 9 API NDDS_Transport_Unshare_RecvResource_Fcn_rrEA
- 大话数据结构 code 第四章 04斐波那契函数_Fibonacci
- 服务器没读取到磁盘阵列信息,服务器磁盘阵列常见问题及解决方法
- Unity2D游戏制作常用方法
- 家长头疼的调皮男孩应该怎么管教
- 升压型 串联LED 背光恒流输出的驱动芯片