2013-06-20 35 views
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); 
    } 
+0

你確定'letter.strokes'不是0嗎? – Undo

+0

另外,當你註釋掉'setNeedsDisplayInRect:'調用時會發生什麼? – Undo

+0

setNeedsDisplayInRect沒有改變任何東西,我在調試器中遍歷它,它至少執行一次。在視圖中什麼也沒有顯示出來。 –

回答

0

我最終通過附加這種觀點和我的其他一個視圖控制器和正確分層他們固定它。