drawRect不想绘制任何东西

jab*_*jab 2 cocoa-touch avfoundation drawrect ios

我在故事板上有一个ViewController.我使用界面构建器在屏幕底部设置工具栏.我已将自定义视图设置为视图覆盖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);
}
Run Code Online (Sandbox Code Playgroud)

occ*_*lus 7

如果你压倒一切,UIView说不要打电话的文件.删除那个电话!众所周知会导致奇怪的行为.[super drawRect]UIView

根据文件:

如果直接子类化UIView,则此方法的实现不需要调用super.但是,如果要子类化其他视图类,则应在实现中的某个时刻调用super.