我试图在可可中绘制一条bezier曲线,并且我得到的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)
答案 0 :(得分:0)
您有controlPoin1: c1
的拼写错误应该是controlPoint1: c1
实际上我刚刚意识到你的目标是AppKit(NSBezierPath)而不是UIKit(UIBezierPath)。
编辑:
对于AppKit使用:-[NSBezierPath curveToPoint: controlPoint1: controlPoint2:]
对于UIKit使用-[UIBezierPath addCurveToPoint: controlPoint1: controlPoint2:]