Question Details

No question body available.

Tags

swiftui realitykit uiviewrepresentable

Answers (1)

Accepted Answer Available
Accepted Answer
August 17, 2025 Score: 0 Rep: 61,060 Quality: High Completeness: 60%

Creating an ARView object inside a ContentView does the trick: ARView isn't frozen now.

import SwiftUI
import RealityKit

struct ARViewContainer : UIViewRepresentable { let arView: ARView

func makeUIView(context: Context) -> ARView { let box = ModelEntity(mesh: .generateBox(size: 0.25)) let anchor = AnchorEntity() anchor.addChild(box) arView.scene.addAnchor(anchor)

box.move( to: Transform(roll: .pi), relativeTo: nil, duration: 15, timingFunction: .linear ) return arView } func updateUIView( view: ARView, context: Context) { } }

struct ContentView : View {
    let arView = ARView(
        frame: .zero,
        cameraMode: .nonAR,
        automaticallyConfigureSession: true
    )
    @State var scaleDown: Bool = false

var body: some View { ZStack { ARViewContainer(arView: arView) .ignoresSafeArea()

Image(systemName: "swift") .resizable() .foregroundStyle(.white) .scaleEffect(scaleDown ? 0.7 : 1.0) .frame(width: 50, height: 50) .position(x: 200.0, y: 100.0) .gesture( DragGesture() .onChanged {
in scaleDown = true Task { try await Task.sleep(nanoseconds: UInt64(1e8)) scaleDown = false } } ) } } }