2013-03-13 138 views
2

我在故事板上有一个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); 
} 
+0

请提供您的'drawRect'代码,可能有错误。您可能希望将其降至最小的非工作示例。 – dasblinkenlight 2013-03-13 12:00:27

回答

7

的文档UIView说,不调用[super drawRect]如果你覆盖了UIView。取消那个电话!已知会引起奇怪的行为。

根据the docs

如果直接继承的UIView,实现此方法 不需要调用超。但是,如果您要继承不同的视图类,则应该在您的 实施中的某个时刻调用super。

+0

那有帮助吗? – occulus 2013-03-14 14:08:35

相关问题