RealityView
RealityView can used developing only for IOS 18+, IPadOS 18+, MacOS15+ and VisionOS 1+.
struct ModelExample: View { var body: some View { RealityView { content in if let robot = try? await ModelEntity(named: "robot") { content.add(robot) } Task { // Asynchronously perform any additional work to configure // the content after the system renders the view. } } } }
The above is a sample code sourced from apple developer documentation.
Here the struct ModelExample cornforms to data type view. The realityview behaves as any other view like
Text(), Button() or EmptyView().
It accepts most of the modifiers of all common views.
realityview is overloaded, hence we have three basic variations.
1. RealityView{ Content in
// necessary 3D content
}
2. RealityView { content in
// necessary 3D content
} update: { content in
// values to updated in the 3D content
}3. RealityView { Content, Attachments in
// necessary 3D contents
} attachments: {
// Put the attachments that will come out as Spatial UI anchored or relative to its parent entity.
}
A single struct can use to render multiple 3D content and more control to developer over the content.
Comments
Post a Comment