我在故事板上有一個ViewController。我使用界面生成器在屏幕底部設置了一個工具欄。我已將自定義視圖設置爲覆蓋drawRect的視圖。然而,對於我的生活,我無法得到任何東西曾經顯示在從drawRect調用的屏幕上。 drawRect本身被稱爲很好,但沒有在屏幕上顯示。drawRect不想繪製任何東西
此外,我有這個ViewController與一個方法,使用AVCaptureSession切換到相機輸入實時視圖的背景。我曾懷疑這可能是錯誤的原因,但在刪除AVCaptureSession的所有引用之後,我仍然無法使其工作。
對不起我寫作和/或缺乏邏輯,我現在沒有任何睡眠。
編輯:這是一個不起作用的小例子。裏面的每個方法都被調用,但沒有任何東西可以顯示。
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
CGContextMoveToPoint(context, 0,0); //start at this point
CGContextAddLineToPoint(context, 100, 100); //draw to this point
// and now draw the Path!
CGContextStrokePath(context);
}
請提供您的'drawRect'代碼,可能有錯誤。您可能希望將其降至最小的非工作示例。 – dasblinkenlight 2013-03-13 12:00:27