【发布时间】:2014-08-19 13:30:29
【问题描述】:
我在很多时间都遇到了一个问题,就是简单地绘制两个单独的形状(例如矩形)
具体来说,我有一个数据源,它是一个数组,这个数组包含包含 CGPoints 的子数组。我要做的只是根据每个子数组绘制路径,并且必须将它们分开。
这是我当前的代码
// for each room
for (int i=0; i<rooms.count; i++) {
// configurations
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetLineWidth(context, 3.0f);
CGContextSetLineJoin(context, kCGLineJoinBevel);
CGContextSetStrokeColorWithColor(context, [UIColor darkGrayColor].CGColor);
// create sub-path
CGMutablePathRef pathRef = CGPathCreateMutable();
// get the points, at least 3
NSArray *corners = rooms[i];
// get the initial point
CGPoint initialPoint = [corners[0] CGPointValue];
CGPathMoveToPoint(pathRef, NULL, initialPoint.x, initialPoint.y);
// draw paths
for (int j=1; j<corners.count; j++) {
CGPoint nextPoint = [corners[j] CGPointValue];
CGPathAddLineToPoint(pathRef, NULL, nextPoint.x, nextPoint.y);
}
// once finish, add the last line to the initial point
CGPathAddLineToPoint(pathRef, NULL, initialPoint.x, initialPoint.y);
CGPathCloseSubpath(pathRef);
CGContextAddPath(context, pathRef);
CGContextStrokePath(context);
// all done, release the path
CGPathCloseSubpath(pathRef);
CGPathRelease(pathRef);
}
换句话说,我的问题。第一个形状的最后一个点将具有与第二个形状的第一个点的路径,而第一个形状的最后一个点具有到第二个形状的第一个点的路径。
有没有人可以帮我找出逻辑的问题在哪里?
任何帮助将不胜感激。非常感谢。
【问题讨论】:
标签: ios cocoa drawrect cgcontext