0
我想繪製和填充Quartz 2d for iPad的簡單路徑。石英路徑不像我所期望的那樣繪製
從類SPTCutPattern下面的方法定義了我要繪製的路徑:
- (void) initDummyCutPattern {
NSArray *piece1Path = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(3, 0)],
[NSValue valueWithCGPoint:CGPointMake(3, 1)],
[NSValue valueWithCGPoint:CGPointMake(2, 1)],
[NSValue valueWithCGPoint:CGPointMake(2, 2)],
[NSValue valueWithCGPoint:CGPointMake(0, 2)],
nil];
SPTPuzzlePiece *Piece1 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:3 andHeightInGrid:2 andLeftInGrid:0 andTopInGrid:0 andBuilt:YES andPathInGrid:piece1Path];
NSArray *piece2Path = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(3, 0)],
[NSValue valueWithCGPoint:CGPointMake(5, 0)],
[NSValue valueWithCGPoint:CGPointMake(5, 5)],
[NSValue valueWithCGPoint:CGPointMake(4, 5)],
[NSValue valueWithCGPoint:CGPointMake(4, 4)],
[NSValue valueWithCGPoint:CGPointMake(2, 4)],
[NSValue valueWithCGPoint:CGPointMake(2, 3)],
[NSValue valueWithCGPoint:CGPointMake(3, 3)],
[NSValue valueWithCGPoint:CGPointMake(3, 2)],
[NSValue valueWithCGPoint:CGPointMake(2, 2)],
[NSValue valueWithCGPoint:CGPointMake(2, 1)],
[NSValue valueWithCGPoint:CGPointMake(3, 1)],
nil];
SPTPuzzlePiece *Piece2 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:3 andHeightInGrid:5 andLeftInGrid:2 andTopInGrid:0 andBuilt:YES andPathInGrid:piece2Path];
NSArray *piece3Path = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(0, 2)],
[NSValue valueWithCGPoint:CGPointMake(3, 2)],
[NSValue valueWithCGPoint:CGPointMake(3, 3)],
[NSValue valueWithCGPoint:CGPointMake(2, 3)],
[NSValue valueWithCGPoint:CGPointMake(2, 4)],
[NSValue valueWithCGPoint:CGPointMake(4, 4)],
[NSValue valueWithCGPoint:CGPointMake(4, 5)],
[NSValue valueWithCGPoint:CGPointMake(0, 5)],
nil];
SPTPuzzlePiece *Piece3 = [[SPTPuzzlePiece alloc] initWithWidthInGrid:4 andHeightInGrid:3 andLeftInGrid:0 andTopInGrid:2 andBuilt:YES andPathInGrid:piece3Path];
self.pieces = [[NSArray alloc] initWithObjects:Piece1, Piece2, Piece3, nil];
}
而且從類SPTPuzzlePieceView此方法這是應該繪製的路徑:
- (void)drawRect:(CGRect)rect
{
int widthUnit = self.frame.size.width/self.puzzlePiece.widthInGrid;
int heightUnit = self.frame.size.height/self.puzzlePiece.heightInGrid;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextMoveToPoint(context, [[puzzlePiece.pathInGrid objectAtIndex:0] CGPointValue].x*widthUnit,
[[puzzlePiece.pathInGrid objectAtIndex:0] CGPointValue].y*heightUnit);
for (NSValue *point in puzzlePiece.pathInGrid) {
CGContextAddLineToPoint(context, [point CGPointValue].x*widthUnit, [point CGPointValue].y*heightUnit);
}
CGContextFillPath(context);
}
我我得到這三個對象,這絕對不是我期望和想要的:
個的對象應該是更多(或更少)是這樣的:
我很抱歉,這些方法是完全斷章取義,所以我希望你能看到什麼,我想做。 drawRect方法被調用來依次繪製我在第一個方法中定義的每個片段對象。
我不明白爲什麼它不繪製我想要的形狀。請幫幫我。
謝謝!
太謝謝你了!我完全明白我現在做錯了什麼。我一定會考慮其他的建議! – mwiederrecht 2012-04-25 20:12:57