UIViews
are known to be layer backed, but not sure about SwiftUI
View. Is there a concept of layer in SwiftUI
which can be added as sublayer, animated, everything you could do with CALayer
?
An object that manages image-based content and allows you to perform animations on that content.
You can create a new CALayer very easily with the following line of code: CALayer *sublayer = [CALayer layer]; Once you have a CALayer, you can set any properties on it you'd like. But remember there's one property you definitely have to set: it's frame (or bounds/position).
Views are the fundamental building blocks of your app's user interface, and the UIView class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle, and handles any interactions with that content.
In the "Building Custom Views with SwiftUI" talk, they demonstrated that Views and Drawing models/interfaces have essentially been combined under the hood in the framework. Therefore, a View has layer like attributes but built onto the View itself rather than a layer abstraction.
Source: https://developer.apple.com/videos/play/wwdc2019/237/
import SwiftUI
import AVFoundation
struct DrawingView: UIViewRepresentable {
private let view = UIView()
var layer: CALayer? {
view.layer
}
func makeUIView(context: Context) -> UIView {
view
}
func updateUIView(_ uiView: UIView, context: Context) { }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With