UIBezierPath畫圓弧的記錄

2021-07-24 10:52:23 字數 2184 閱讀 4736

文中的圖很重要!!!

根據下文,完成了下圖的mask:

**如下:

cgsize size = self.size;

// 畫路徑

uibezierpath *maskpath = [uibezierpath bezierpath];

// bottom line

[maskpath movetopoint:cgpointmake(size.width, 0)];

[maskpath addlinetopoint:cgpointmake(size.width, 91)];

[maskpath addarcwithcenter:cgpointmake(size.width, 99.f)

radius:pixel_8

startangle:1.5*m_pi endangle:0.5*m_pi

clockwise:no];

[maskpath addlinetopoint:cgpointmake(size.width, size.height)];

[maskpath addlinetopoint:cgpointmake(0, size.height)];

[maskpath addlinetopoint:cgpointmake(0, 107.f)];

[maskpath addarcwithcenter:cgpointmake(0, 99.f)

radius:pixel_8

startangle:0.5*m_pi endangle:1.5*m_pi

clockwise:no];

[maskpath addlinetopoint:cgpointmake(0, 0)];

[maskpath addlinetopoint:cgpointmake(size.width, 0)];

[maskpath closepath];

// 畫出 形狀

cashapelayer *masklayer = [cashapelayer new];

masklayer.path = maskpath.cgpath;

self.layer.mask = masklayer;

------------------華麗的分割線-------------------

uibezierpath通過

- (void)addarcwithcenter:(cgpoint)center radius:(cgfloat)radius startangle:(cgfloat)startangle endangle:(cgfloat)endangle clockwise:(bool)clockwise

可以畫出一段弧線。

看下各個引數的意義:

center:圓心的座標

radius:半徑

startangle:起始的弧度

endangle:圓弧結束的弧度

clockwise:yes為順時針,no為逆時針

方法裡面主要是理解startangle與endangle,剛開始我搞不清楚一段圓弧從哪算起始和終止,比如弧度為0的話,是從上下左右哪個點開始算

看了下面這張圖就明了了

看出0pi就是指圓最右邊開始計算的,順時針依次為m_pi/2,m_pi,m_pi*1.5

明白這個,用bezierpath畫圓弧就簡單了

比如要畫上圖加粗的那段就是:

[html]view plain

copy

uibezierpath *

path

= [[uibezierpath alloc] init];    

[path addarcwithcenter:center    

radius:radius    

startangle:m_pi*1.1    

endangle:m_pi*1.9    

clockwise:yes];    

UIBezierPath畫圓弧的記錄

uibezierpath通過 void addarcwithcenter cgpoint center radius cgfloat radius startangle cgfloat startangle endangle cgfloat endangle clockwise bool clock...

UIBezierPath 畫圓弧(角度問題)

uibezierpath通過 void addarcwithcenter cgpoint center radius cgfloat radius startangle cgfloat startangle endangle cgfloat endangle clockwise bool clock...

UIBezierPath畫圓弧的記錄

uibezierpath通過 void addarcwithcenter cgpoint center radius cgfloat radius startangle cgfloat startangle endangle cgfloat endangle clockwise bool clock...