< UIKit >

UIBezierPath.h

2019-03-18  本文已影响0人  zhYx_

#if USE_UIKIT_PUBLIC_HEADERS || !__has_include(<UIKitCore/UIBezierPath.h>)
//
//  UIBezierPath.h
//  UIKit
//
//  Copyright (c) 2009-2018 Apple Inc. All rights reserved.
//
#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
};

#pragma mark - 贝塞尔曲线
#pragma mark -
/*
 - UIBezierPath
    由直线和曲线线段组成的路径,可以在自定义View中呈现这些线段
 - 概述
    您最初使用此类仅指定路径的几何.路径可以定义简单的形状,例如矩形/椭圆/弧形,或者它们可以定义包含直线和曲线线段混合的复杂多边形.定义形状后,可以使用此类的其他方法在当前图形上下文中呈现路径
    UIBezierPath对象将路径的几何与在渲染期间描述路径的属性组合在一起,您可以单独设置几何和属性,并可以相互独立地更改它们.按照您希望的方式配置对象后,您可以告诉它在当前上下文中绘制自己.由于创建-配置-渲染过程都是不同的步骤,因此可以在代码中轻松地重用Bézier路径对象.您甚至可以使用同一个对象多次渲染相同的形状,可能会更改连续绘图调用之间的渲染选项
    您可以通过操纵路径的当前点来设置路径的几何.创建新的空路径对象时,当前点未定义,必须明确设置.要在不绘制线段的情况下移动当前点,请使用moveToPoint:方法.所有其他方法都会在路径中添加线段或曲线段.添加新段的方法始终假设您从当前点开始并以您指定的某个新点结束.添加段后,新段的结束点将自动成为当前点
    单个Bézier路径对象可以包含任意数量的打开或关闭子路径,其中每个子路径表示一系列连接的路径段.调用closePath方法通过添加从当前点到子路径中第一个点的直线段来关闭子路径.调用moveToPoint:方法结束当前子路径(不关闭它)并设置下一个子路径的起始点.Bézier路径对象的子路径共享相同的绘图属性,必须作为一组进行操作.要绘制具有不同属性的子路径,必须将每个子路径放在其自己的UIBezierPath对象中
    配置Bézier路径的几何和属性后,使用笔触和填充方法在当前图形上下文中绘制路径.笔划方法使用当前笔划颜色和Bézier路径对象的属性来跟踪路径的轮廓.类似地,填充方法使用当前填充颜色填充路径包围的区域(使用UIColor设置笔触和填充颜色)
    除了使用Bézier路径对象绘制形状之外,您还可以使用它来定义新的剪切区域.addClip方法将路径对象表示的形状与图形上下文的当前剪切区域相交.在后续绘制期间,只有位于新交叉区域内的内容才实际呈现给图形上下文
 */
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; // rounds all corners with the same horizontal and vertical radius
+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath;
// 对象方法
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;

// 设置 路径(返回一个不可变的CGPathRef,设置此属性将忽略CGMutablePathRef的设置)
@property(nonatomic) CGPathRef CGPath;
- (CGPathRef)CGPath NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;

/* 路径建设 */
/**
 将当前点移动到指定点

 @param point 目的点坐标
 */
- (void)moveToPoint:(CGPoint)point;
/**
 从当前点到指定点画一条直线

 @param 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;
/**
 追加路径

 @param bezierPath 追加的路径
 */
- (void)appendPath:(UIBezierPath *)bezierPath;
/**
 反转路径(创建并返回具有当前路径的反转内容的新Bézier路径对象)

 @return 反转后的路径
 */
- (UIBezierPath *)bezierPathByReversingPath NS_AVAILABLE_IOS(6_0);
/**
 转变路径(旋转/平移/缩放等)

 @param transform 转换方式
 */
- (void)applyTransform:(CGAffineTransform)transform;

/* 路径信息 */
// 获取 路径是否具有任何有效元素
@property(readonly,getter=isEmpty) BOOL empty;
// 获取 路径的尺寸
@property(nonatomic,readonly) CGRect bounds;
// 获取 路径的当前点
@property(nonatomic,readonly) CGPoint currentPoint;
/**
 判断一个点是否是路径的当前点

 @param point 要判断的点坐标
 @return 是/否
 */
- (BOOL)containsPoint:(CGPoint)point;

/* 绘图属性 */
// 设置 路径的线宽
@property(nonatomic) CGFloat lineWidth;
// 设置 路径起始点样式
@property(nonatomic) CGLineCap lineCapStyle;
// 设置 路径拐点样式
@property(nonatomic) CGLineJoin lineJoinStyle;
// 设置 拐点限制值(lineJoinStyle是kCGLineJoinMiter时有效)
@property(nonatomic) CGFloat miterLimit;
// 设置 弯曲路径渲染精度
@property(nonatomic) CGFloat flatness;
// 设置 是否启用偶数填充规则(默认:NO)
@property(nonatomic) BOOL usesEvenOddFillRule;

/**
 设置 路径的虚线模式

 @param pattern 虚线样式(C样式的浮点值数组,第一个值为实线距离,第二个值为间隔距离,以此类推)
 @param count 取模式中值的数量
 @param phase 相位值(开始绘制图案的偏移量,沿着虚线图案的点测量;例如,图案5-2-3-2的相位值6将导致绘图在第一个间隙的中间开始)
 */
- (void)setLineDash:(nullable const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)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
#else
#import <UIKitCore/UIBezierPath.h>
#endif

上一篇下一篇

猜你喜欢

热点阅读