【发布时间】:2016-02-21 10:00:13
【问题描述】:
theLen = [NSBezierPath bezierPath];
[theLen moveToPoint:NSMakePoint(_frame.size.width/2 + base / 2 , _frame.size.height/2 - (diameter / 2))];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 - base / 2 , _frame.size.height/2 - (diameter / 2))];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 - (thickness / 2 ) , _frame.size.height/2)];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 - base / 2 , _frame.size.height/2 + (diameter / 2))];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 + base / 2 , _frame.size.height/2 + (diameter / 2))];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 + (thickness / 2 ) , _frame.size.height/2)];
[theLen closePath];
theLen.lineWidth = 2;
[theLen stroke];
[theLen fill];
鉴于此代码,您将如何简化它?我正在尝试学习如何简化代码,而我所能想到的就是把它变成......
float commonNSPoint[4];
commonNSPoint[0] = _frame.size.width/2 + base / 2;
commonNSPoint[1] = _frame.size.width/2 - base / 2;
commonNSPoint[2] = _frame.size.height/2 - (diameter / 2);
commonNSPoint[3] = _frame.size.height/2 + (diameter / 2);
theLen = [NSBezierPath bezierPath];
[theLen moveToPoint:NSMakePoint( commonNSPoint[0], commonNSPoint[2])];
[theLen lineToPoint:NSMakePoint(commonNSPoint[1], commonNSPoint[2])];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 - (thickness / 2 ) , _frame.size.height/2)];
[theLen lineToPoint:NSMakePoint(commonNSPoint[1], commonNSPoint[3])];
[theLen lineToPoint:NSMakePoint( commonNSPoint[0], commonNSPoint[3])];
[theLen lineToPoint:NSMakePoint(_frame.size.width/2 + (thickness / 2 ) , _frame.size.height/2)];
[theLen closePath];
[theLen closePath];
theLen.lineWidth = 2;
[theLen stroke];
[theLen fill];
这并没有真正帮助我,因为 NSBezierPath 或 UIBezierPath 的点位置并不完全相同。这也使代码看起来更混乱。
你们将如何简化这样的 NSBezierPath 或 UIBezierPath。任何事情都会有所帮助(因为我的程序基于不同的 NSPoint 值和许多 NSBezierPath 绘图)。
谢谢
【问题讨论】:
标签: objective-c uibezierpath nsbezierpath