zoukankan      html  css  js  c++  java
  • iOS之UIBezierPath贝塞尔曲线属性简介

    #import <Foundation/Foundation.h>
    #import <CoreGraphics/CoreGraphics.h>
    #import <UIKit/UIKitDefines.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
        UIRectCornerTopLeft     = 1 << 0,
        UIRectCornerTopRight    = 1 << 1,
        UIRectCornerBottomLeft  = 1 << 2,
        UIRectCornerBottomRight = 1 << 3,
        UIRectCornerAllCorners  = ~0UL
    };
    
    NS_CLASS_AVAILABLE_IOS(3_2) @interface UIBezierPath : NSObject<NSCopying, NSSecureCoding>
    
    //初始化
    + (instancetype)bezierPath;
    
    //初始化一个矩形路径
    + (instancetype)bezierPathWithRect:(CGRect)rect;
    
    //初始化一个椭圆路径,相切矩形的四条边。
    + (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
    
    //初始化一个圆角矩形,矩形区域 边角半径
    + (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;
    
    /**
     初始化圆角矩形
    
     @param rect 矩形区域
     @param corners 枚举:哪个角是圆角(多个时用 ‘|’分开)
     @param cornerRadii 圆角半径
     */
    + (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
    
    /**
     初始化一个开放圆弧路径
    
     @param center 圆心
     @param radius 半径
     @param startAngle 开始角度(0-M_PI)
     @param endAngle 结束角度
     @param clockwise 是否顺时针
     */
    + (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
    
    //根据CGPath初始化对象
    + (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;
    
    - (instancetype)init NS_DESIGNATED_INITIALIZER;
    - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
    
    //设置路径,也可以获取一个不可变的路径!
    @property(nonatomic) CGPathRef CGPath;
    - (CGPathRef)CGPath NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;
    
    //移动到当前点
    - (void)moveToPoint:(CGPoint)point;
    
    //到当前点画一条直线
    - (void)addLineToPoint:(CGPoint)point;
    
    /**
     追加画一条三次贝塞尔曲线
    
     @param endPoint 结束点
     @param controlPoint1 控制点1
     @param controlPoint2 控制点2
     */
    - (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2;
    
    /**
     追加画一条二次贝塞尔曲线
    
     @param endPoint 结束点
     @param controlPoint 控制点
     */
    - (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint;
    
    /**
     追加一条圆弧
    
     @param center 中心点
     @param radius 半径
     @param startAngle 开始角度
     @param endAngle 结束角度
     @param clockwise 是否顺时针
     */
    - (void)addArcWithCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise NS_AVAILABLE_IOS(4_0);
    
    //闭合路径
    - (void)closePath;
    
    //去除所有路径
    - (void)removeAllPoints;
    
    //追加bezierPath
    - (void)appendPath:(UIBezierPath *)bezierPath;
    
    // 将原来的UIBezierPath反方向绘制(两个路径一样,方向不一样)
    - (UIBezierPath *)bezierPathByReversingPath NS_AVAILABLE_IOS(6_0);
    
    // 进行放射,2D变换
    - (void)applyTransform:(CGAffineTransform)transform;
    
    // Path info
    @property(readonly,getter=isEmpty) BOOL empty;      //路径是否为空
    @property(nonatomic,readonly) CGRect bounds;        //路径区域
    @property(nonatomic,readonly) CGPoint currentPoint; //当前点
    - (BOOL)containsPoint:(CGPoint)point;               //是否包含某个点
    
    // Drawing properties
    @property(nonatomic) CGFloat lineWidth;             //线宽
    @property(nonatomic) CGLineCap lineCapStyle;        //曲线终点样式 枚举
    @property(nonatomic) CGLineJoin lineJoinStyle;      //曲线连接处样式 枚举
    @property(nonatomic) CGFloat miterLimit;    // 连接处lineJoinStyle值是kCGLineJoinMiter,内角与外角距离,最大限制10
    @property(nonatomic) CGFloat flatness;      //渲染精度(默认0.6),数值越小,精度越高也越耗时!
    @property(nonatomic) BOOL usesEvenOddFillRule; // 是否使用基偶填充规则,(默认是NO 非零规则)
    
    /**
     绘制虚线路径
    
     @param pattern C语言数组 CGFloat xx[] = {线段长度,间隙长度}; 轮流
     @param count 数组个数
     @param phase 从第几个数开始绘制
     */
    - (void)setLineDash:(nullable const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase;
    
    /**
     获取虚线样式
    
     @param pattern 数组(空间必须大于路径空间)
     @param count 数组个数
     @param phase 开始位数
     */
    - (void)getLineDash:(nullable CGFloat *)pattern count:(nullable NSInteger *)count phase:(nullable CGFloat *)phase;
    
    - (void)fill;       //填充
    - (void)stroke;     //画线
    
    /**
     混合填充
    
     @param blendMode 填充模式 枚举
     @param alpha 透明度
     */
    - (void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
    
    /**
     混合画线
    
     @param blendMode 模式 枚举
     @param alpha 透明度
     */
    - (void)strokeWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
    
    //剪切路径 之后路径只能在区域里画线
    - (void)addClip;
    
    @end
    
    NS_ASSUME_NONNULL_END
  • 相关阅读:
    CSS实现雨滴动画效果
    大型网站架构系列:电商网站架构案例
    CSS 不定宽高的垂直水平居中方式总汇
    js中尺寸类样式
    Tiling
    排序二叉树
    算术表达式的转换
    Area
    catch that cow
    R中双表操作学习[转载]
  • 原文地址:https://www.cnblogs.com/xianfeng-zhang/p/7736508.html
Copyright © 2011-2022 走看看