drawRect不想绘制任何东西
问题描述:
我在故事板上有一个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