我可以在iOS中使用UIBezierPath's
方法addQuadCurveToPoint
绘制四边形曲线,但无法在NSBezierPath中找到相同的方法。
我只能在NSBezierPath类中看到以下方法,
- moveToPoint:(NSPoint)point;
- lineToPoint:(NSPoint)point;
- curveToPoint:(NSPoint)endPoint
controlPoint1:(NSPoint)controlPoint1
controlPoint2:(NSPoint)controlPoint2;
- closePath;
有没有办法在OS X环境中绘制四边形曲线?
答案 0 :(得分:0)
致电path.addQuadCurve(to: endPoint, controlPoint: controlPoint)
,
下面的代码
extension NSBezierPath{
func addQuadCurve(to endPoint: CGPoint, controlPoint: CGPoint){
let startPoint = self.currentPoint
let controlPoint1 = CGPoint(x: (startPoint.x + (controlPoint.x - startPoint.x) * 2.0/3.0), y: (startPoint.y + (controlPoint.y - startPoint.y) * 2.0/3.0))
let controlPoint2 = CGPoint(x: (endPoint.x + (controlPoint.x - endPoint.x) * 2.0/3.0), y: (endPoint.y + (controlPoint.y - endPoint.y) * 2.0/3.0))
curve(to: endPoint, controlPoint1: controlPoint1, controlPoint2: controlPoint2)
}
}
感谢有节奏的拳头