UIBezierPath + bezierPathWithArcCenter

UIBezierPath + bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:
Creates and returns a new UIBezierPath object initialized with an arc of a circle.

Declaration
SWIFT
convenience init(arcCenter center: CGPoint,
          radius radius: CGFloat,
      startAngle startAngle: CGFloat,
        endAngle endAngle: CGFloat,
       clockwise clockwise: Bool)
OBJECTIVE-C
+ (instancetype)bezierPathWithArcCenter:(CGPoint)center
                                 radius:(CGFloat)radius
                             startAngle:(CGFloat)startAngle
                               endAngle:(CGFloat)endAngle
                              clockwise:(BOOL)clockwise

Parameters
center
Specifies the center point of the circle (in the current coordinate system) used to define the arc.
radius
Specifies the radius of the circle used to define the arc.
startAngle
Specifies the starting angle of the arc (measured in radians).
endAngle
Specifies the end angle of the arc (measured in radians).
clockwise
The direction in which to draw the arc.
Return Value
A new path object with the specified arc.

Discussion
This method creates an open subpath. The created arc lies on the perimeter of the specified circle. When drawn in the default coordinate system, the start and end angles are based on the unit circle shown in Figure 1. For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the clockwise parameter to YES draws the bottom half of the circle. However, specifying the same start and end angles but setting the clockwise parameter set to NO draws the top half of the circle.

Figure 1Angles in the default coordinate system
image: ../Art/radians_circle.png
After calling this method, the current point is set to the point on the arc at the end angle of the circle.

Availability
Available in iOS 3.2 and later.


可以使用贝塞尔曲线和 CAKeyframeAnimation 来构建动画。

// 路径曲线
UIBezierPath *movePath = [UIBezierPath bezierPath];
...
// 关键帧
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为您介绍如何使用UIBezierPath画聊天气泡。 首先,我们需要创建一个UIView作为聊天气泡的容器,并设置它的背景色和圆角。 然后,我们可以创建一个UIBezierPath对象,使用move(to:)方法将笔触移动到气泡的左下角,然后使用addLine(to:)方法画出气泡的左侧、顶部和右侧的线条。接着,我们可以使用addArc(withCenter:radius:startAngle:endAngle:clockwise:)方法在气泡的右下角添加一个圆角。 最后,我们可以使用CAShapeLayer将UIBezierPath对象渲染到UIView上,实现聊天气泡的绘制。 以下是示例代码: ```swift let bubbleView = UIView() bubbleView.backgroundColor = UIColor(red: 0.93, green: 0.93, blue: 0.93, alpha: 1) bubbleView.layer.cornerRadius = 10 bubbleView.clipsToBounds = true let bubblePath = UIBezierPath() bubblePath.move(to: CGPoint(x: 10, y: bubbleView.bounds.height - 10)) bubblePath.addLine(to: CGPoint(x: 10, y: 10)) bubblePath.addLine(to: CGPoint(x: bubbleView.bounds.width - 30, y: 10)) bubblePath.addLine(to: CGPoint(x: bubbleView.bounds.width - 20, y: 0)) bubblePath.addLine(to: CGPoint(x: bubbleView.bounds.width - 10, y: 10)) bubblePath.addLine(to: CGPoint(x: bubbleView.bounds.width - 10, y: bubbleView.bounds.height - 10)) bubblePath.addArc(withCenter: CGPoint(x: bubbleView.bounds.width - 20, y: bubbleView.bounds.height - 10), radius: 10, startAngle: 0, endAngle: CGFloat.pi / 2, clockwise: true) bubblePath.addArc(withCenter: CGPoint(x: bubbleView.bounds.width - 20, y: bubbleView.bounds.height - 20), radius: 10, startAngle: CGFloat.pi / 2, endAngle: CGFloat.pi, clockwise: true) bubblePath.addArc(withCenter: CGPoint(x: bubbleView.bounds.width - 30, y: bubbleView.bounds.height - 10), radius: 10, startAngle: CGFloat.pi, endAngle: CGFloat.pi * 3 / 2, clockwise: true) bubblePath.close() let shapeLayer = CAShapeLayer() shapeLayer.path = bubblePath.cgPath bubbleView.layer.mask = shapeLayer ``` 以上代码将创建一个灰色的聊天气泡,带有圆角和三角形尾巴。您可以根据需要调整气泡的颜色、形状和大小。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值