2
votes

I have a ViewController on storyboard. I have used the interface builder to set a toolbar at the bottom of the screen. I have set the custom view to a view overrides drawRect. However, for the life of me, I cannot get anything ever to show up on screen called from that drawRect. drawRect itself is called just fine, but nothing shows up on screen.

Also, I have this ViewController with a method that uses AVCaptureSession to toggle its background to a live view from camera input. I had suspected that this might have been the cause for error, but after removing all references of AVCaptureSession, I still cannot get this to work.

Sorry for my writing and/or lack of logic, I don't have any sleep right now.

Edit: Here is a small example of code that won't work. Every method inside gets called, but nothing is to show.

- (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);
}
1
Please provide your drawRect code, it's possible that the error is there. You may want to reduce it to the smallest non-working example.Sergey Kalinichenko

1 Answers

7
votes

The documentation for UIView says to not call [super drawRect] if you're overriding UIView. Remove that call! It's been known to cause strange behaviour.

According to the docs:

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.