LiYanan2004
LiYanan2004

Reputation: 113

How to render content of CALayer and sync with it in real-time

I'm creating a backdrop layer.

I can

But

Imagine I have a ScrollView, when user scrolls the view, the rendered content is one-frame behind the underlying view. Making the experience terrible.

Screenshots

gif

screenshot-of-the-problem

Code

TimelineView(.animation) { timeline in
    Canvas { context, size in
        let _ = timeline.date // Update content with DisplayLink.
        context.withCGContext { cgContext in
            for layer in renderer.backdropLayers {
                layer.render(in: cgContext)
            }
        }
    }
}

How can I improve the rendering process?

I know there is a private class called CABackdropLayer available to use. But I'm doing a SwiftUI App. Ideally, I can create a backdrop effect view and apply custom Shader to it.

You can check out my post on Twitter (or X) for what I'm building now.

Upvotes: 0

Views: 162

Answers (0)

Related Questions