drawRect不想绘制任何东西

我有一个故事板上的ViewController。 我已经使用界面生成器在屏幕底部设置了一个工具栏。 我已经将自定义视图设置为一个视图覆盖drawRect。 但是,在我的生活中,我从来没有得到任何东西在屏幕上显示,从drawRect调用。 drawRect本身被称为很好,但没有任何显示在屏幕上。

此外,我有这个ViewController的方法,使用AVCaptureSession切换到相机input实时视图的背景。 我怀疑这可能是错误的原因,但删除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); } 

UIView的文档说,如果你重写UIView ,不要调用[super drawRect] 。 删除那个电话! 据了解,这会造成奇怪的行为。

根据文件 :

如果直接inheritanceUIView,则此方法的实现不需要调用super。 但是,如果您inheritance不同的视图类,则应该在实现中的某个位置调用super。