0
我有一个形状,有几个UIBezierPaths,我试图在我的视图中绘制,他们没有显示出来。你能告诉我我做错了什么吗?绘制抚摸UIBezierPath在drawRect没有显示
// 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);
}
你确定'letter.strokes'不是0吗? – Undo
另外,当你注释掉'setNeedsDisplayInRect:'调用时会发生什么? – Undo
setNeedsDisplayInRect没有改变任何东西,我在调试器中遍历它,它至少执行一次。在视图中什么也没有显示出来。 –