ios 動畫系列之六------UIBezierPath貝塞爾弧線常用方法記


//根據一個矩形畫曲線

+ (UIBezierPath *)bezierPathWithRect:(CGRect)rect

 

//根據矩形框的內切圓畫曲線

+ (UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect

 

//根據矩形畫帶圓角的曲線

+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius

 

//在矩形中,可以針對四角中的某個角加圓角

+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii

參數:

corners:枚舉值,可以選擇某個角

cornerRadii:圓角的大小

 
//以某個中心點畫弧線 
+ ( UIBezierPath   *)bezierPathWithArcCenter:( CGPoint )center radius:( CGFloat )radius startAngle:( CGFloat )startAngle endAngle:( CGFloat )endAngle clockwise:( BOOL )clockwise;

參數:

center:弧線中心點的坐標

radius:弧線所在圓的半徑

startAngle:弧線開始的角度值

endAngle:弧線結束的角度值

clockwise:是否順時針畫弧線

 

//畫二元曲線,一般和moveToPoint配合使用

- (void)addQuadCurveToPoint:(CGPoint)endPoint controlPoint:(CGPoint)controlPoint

參數:

endPoint:曲線的終點

controlPoint:畫曲線的基准點

例子:UIBezierPath *movePath = [UIBezierPath bezierPath];     

      CGPoint fromPoint = self.imageView.center;     

      CGPoint endPoint = CGPointMake(280, 400);    

      [movePath moveToPoint:fromPoint];    //開始點

      [movePath addQuadCurveToPoint:endPoint controlPoint:CGPointMake(280,0)]; //畫二元曲線,結束點、控制點

 

 

//以三個點畫一段曲線,一般和moveToPoint配合使用

- (void)addCurveToPoint:(CGPoint)endPoint controlPoint1:(CGPoint)controlPoint1 controlPoint2:(CGPoint)controlPoint2

參數:

endPoint:曲線的終點

controlPoint1:畫曲線的第一個基准點

controlPoint2:畫曲線的第二個基准點

 

//自己創建一段曲線

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 100)];//開始點
[path addLineToPoint:CGPointMake(300, 100)];//向這條線上加點

[path addLineToPoint:CGPointMake(300, 200)];
   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM