Post

Replies

Boosts

Views

Activity

Modal presentation of SwiftUI view with TextField leads to frozen UI, missing keyboard and memory leak
Hello, I’m trying to present my custom SwiftUI dialog with text field in UIKit with modalPresentationStyle = .overFullScreen, but it leads to the UI being completely frozen once I select the TextField and memory constantly leaking. The minimal reproducible code is: class ModalBugViewController: UIViewController { var hostingController: UIHostingController<Content>! struct Content: View { @State private var text = "" var body: some View { ZStack { Color.black.opacity(0.5).ignoresSafeArea() VStack { TextField("Test", text: $text) .textFieldStyle(.roundedBorder) .padding() } } } } override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .clear hostingController = UIHostingController(rootView: Content()) addChild(hostingController) view.addSubview(hostingController.view) hostingController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor) ]) hostingController.didMove(toParent: self) } } And then in UIKit source view: let viewController = ModalBugViewController() viewController.modalPresentationStyle = .overFullScreen present(viewController, animated: true) The bug is reproducible on iOS 18 - 26.1, even on the simulator, although on iOS 26 it's in landscape mode only. Is there some workaround for this issue that doesn't involve rewriting the whole dialog in UIKit?
1
0
102
Nov ’25
Collision handling between the entity and the real environment objects and planes in RealityKit
I'm trying to achieve a similar behaviour to the native AR preview app on iOS when we can place a model and once we move or rotate it, it automatically detects the obstacles and gives a haptic feedback, and doesn't go through the walls. I'm using the devices with LiDAR only. Here is what I have so far: Session setup private func configureWorldTracking() { let configuration = ARWorldTrackingConfiguration() configuration.planeDetection = [.horizontal, .vertical] configuration.environmentTexturing = .automatic if ARWorldTrackingConfiguration.supportsSceneReconstruction(.meshWithClassification) { configuration.sceneReconstruction = .meshWithClassification } let frameSemantics: ARConfiguration.FrameSemantics = [.smoothedSceneDepth, .sceneDepth] if ARWorldTrackingConfiguration.supportsFrameSemantics(frameSemantics) { configuration.frameSemantics.insert(frameSemantics) } session.run(configuration) session.delegate = self arView.debugOptions.insert(.showSceneUnderstanding) arView.renderOptions.insert(.disableMotionBlur) arView.environment.sceneUnderstanding.options.insert([.collision, .physics, .receivesLighting, .occlusion]) } Custom entity: class CustomEntity: Entity, HasModel, HasCollision, HasPhysics { var modelName: String = "" private var cancellable: AnyCancellable? init(modelName: String) { super.init() self.modelName = modelName self.name = modelName load() } required init() { fatalError("init() has not been implemented") } deinit { cancellable?.cancel() } func load() { cancellable = Entity.loadModelAsync(named: modelName + ".usdz") .sink(receiveCompletion: { result in switch result { case .finished: break case .failure(let failure): debugPrint(failure.localizedDescription) } }, receiveValue: { modelEntity in modelEntity.generateCollisionShapes(recursive: true) self.model = modelEntity.model self.collision = modelEntity.collision self.collision?.filter.mask.formUnion(.sceneUnderstanding) self.physicsBody = modelEntity.physicsBody self.physicsBody?.mode = .kinematic }) } Entity loading and placing let tapLocation = sender.location(in: arView) guard let raycastResult = arView.raycast(from: tapLocation, allowing: .estimatedPlane, alignment: .horizontal).first else { return } let entity = CustomEntity(modelName: modelName) let anchor = AnchorEntity(world: raycastResult.worldTransform) anchor.name = entity.name anchor.addChild(entity) arView.scene.addAnchor(anchor) arView.installGestures([.rotation, .translation], for: entity) This loads my model properly and allows me to move it and rotate as well, but I cannot figure out how to handle the collision handling with the real environment like walls and interrupt gestures once my model starts going thought it?
0
1
665
Sep ’23