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沒有改變任何東西,我在調試器中遍歷它,它至少執行一次。在視圖中什麼也沒有顯示出來。 –