addCurveToPoint 因 EXC_BAD_INSTRUCTION 而崩溃

addCurveToPoint crashing with EXC_BAD_INSTRUCTION

我试图在 cocoa 中绘制一条贝塞尔曲线,但得到的 EXC_BAD_INSTRUCTION 似乎根本没有任何意义。

这是我的代码:

NSBezierPath *path = [NSBezierPath bezierPath];
[path setLineWidth: 1.0f];

NSPoint a = NSMakePoint(0, 0);
NSPoint c1 = NSMakePoint(0, 50);
NSPoint c2 = NSMakePoint(50, 100);
NSPoint b = NSMakePoint(100, 100);

[path moveToPoint:a];
[path addCurveToPoint: b controlPoint1:c1 controlPoint2:c2];

[[NSColor colorWithDeviceRed:1 green:0 blue:0 alpha:1] set];

[path stroke];

我的应用程序在执行以下行时崩溃:

[path addCurveToPoint: b controlPoin1:c1 controlPoint2:c2];

并且 Xcode 告诉我它在我的主循环中崩溃了:

[NSApp runModalSession:modalSession];

错误输出如下:

2016-12-08 04:38:35.344601 unit_tests[10606:777278] -[NSBezierPath addCurveToPoint:controlPoint1:controlPoint2:]: unrecognized selector sent to instance 0x100428fa0

(lldb)

你打错了 controlPoin1: c1 应该是 controlPoint1: c1

实际上我刚刚意识到您的目标是 AppKit (NSBezierPath) 而不是 UIKit (UIBezierPath)。

编辑:

对于 AppKit 使用:-[NSBezierPath curveToPoint: controlPoint1: controlPoint2:]

对于 UIKit 使用 -[UIBezierPath addCurveToPoint: controlPoint1: controlPoint2:]