1

我有一个形状,它有一些 UIBezierPaths 我试图在我的视图中绘制它们并没有显示出来。你能告诉我我做错了什么吗?

// Function to perform custom drawing.
- (void)drawRect:(CGRect)rect
{
    CGContextRef currentContext = UIGraphicsGetCurrentContext();

    for (Stroke* stroke in letter.strokes)
    {
        if (letter.strokes[letter.currentStroke] == stroke)
        {
            [stroke.path stroke];
        }
        else
        {
            [stroke.path strokeWithBlendMode:kCGBlendModeNormal alpha:0.5f];
        }
        [self setNeedsDisplayInRect:stroke.path.bounds];
    }
}

也不起作用的新代码:

for (Stroke* stroke in letter.strokes)
    {
        UIBezierPath* path = stroke.path;

        [[UIColor blackColor] setStroke];

        [[UIColor redColor] setFill];

        CGContextRef currentContext = UIGraphicsGetCurrentContext();

        CGContextSaveGState(currentContext);

        CGContextTranslateCTM(currentContext, 50, 50);

        path.lineWidth = 5;

        if (letter.strokes[letter.currentStroke] == stroke)
        {
            [path fill];
            [path stroke];
        }
        else
        {
            [stroke.path strokeWithBlendMode:kCGBlendModeNormal alpha:0.5f];
        }
        [self setNeedsDisplayInRect:stroke.path.bounds];

        CGContextRestoreGState(currentContext);
    }
4

1 回答 1

0

我最终通过将这个视图和我的另一个视图附加到视图控制器并正确分层来修复它。

于 2013-06-21T18:37:44.387 回答