Search code examples
ioscocoa-touchcalayer

Calling drawRect to draw on top of CALayer?


I current have a view with its CALayer as an AVCapturePreviewLayer, to output video from the iphone's camera. I would like to call drawRect and draw on top of this video output, like draw a simple line on the screen with the current camera capture in the background. The problem is that everything in drawRect appears behind the AVCapturePreviewLayer instead of in front of it. Is there a way to implement this functionality? Preferably without using multiple views?


Solution

  • Add a sublayer to the view's layer:

    [view.layer addSublayer:...];
    

    Then draw what you want on the sublayer.