Discuss Spatial Computing on Apple Platforms.

Post

Replies

Boosts

Views

Activity

Tapping once with both hands only works sometimes in visionOS
Hello! I have an iOS app where I am looking into support for visionOS. I have a whole bunch of gestures set up using UIGestureRecognizer and so far most of them work great in visionOS! But I do see something odd that I am not sure can be fixed on my end. I have a UITapGestureRecognizer which is set up with numberOfTouchesRequired = 2 which I am assuming translates in visionOS to when you tap your thumb and index finger on both hands. When I tap with both hands sometimes this tap gesture gets kicked off and other times it doesn't and it says it only received one touch when it should be two. Interestingly, I see this behavior in Apple Maps where tapping once with both hands should zoom out the map, which only works sometimes. Can anyone explain this or am I missing something?
0
0
69
1d
Not being able to set maximum window size for Views under different tabs
On TikTok on Vision Pro, the home page has different minimum and maximum window heights and widths compared to the search page. Now I am able to set minimum window size for different tab views but maximum size doesn't seem to work Code: // WindowSizeModel.swift import Foundation import SwiftUI enum TabType { case home case search case profile } @Observable class WindowSizeModel { var minWidth: CGFloat = 400 var maxWidth: CGFloat = 500 var minHeight: CGFloat = 400 var maxHeight: CGFloat = 500 func setWindowSize(for tab: TabType) { switch tab { case .home: configureWindowSize(minWidth: 400, maxWidth: 500, minHeight: 400, maxHeight: 500) case .search: configureWindowSize(minWidth: 300, maxWidth: 800, minHeight: 300, maxHeight: 800) case .profile: configureWindowSize(minWidth: 800, maxWidth: 1000, minHeight: 800, maxHeight: 1000) } } private func configureWindowSize(minWidth: CGFloat, maxWidth: CGFloat, minHeight: CGFloat, maxHeight: CGFloat) { self.minWidth = minWidth self.maxWidth = maxWidth self.minHeight = minHeight self.maxHeight = maxHeight } } // tiktokForSpacialModelingApp.swift import SwiftUI @main struct tiktokForSpacialModelingApp: App { @State private var windowSizeModel: WindowSizeModel = WindowSizeModel() var body: some Scene { WindowGroup { MainView() .frame( minWidth: windowSizeModel.minWidth, maxWidth: windowSizeModel.maxWidth, minHeight: windowSizeModel.minHeight, maxHeight: windowSizeModel.maxHeight) .environment(windowSizeModel) } .windowResizability(.contentSize) } } // MainView.swift import SwiftUI import RealityKit struct MainView: View { @State private var selectedTab: TabType = TabType.home @Environment(WindowSizeModel.self) var windowSizeModel; var body: some View { @Bindable var windowSizeModel = windowSizeModel TabView(selection: $selectedTab) { Tab("Home", systemImage: "play.house", value: TabType.home) { HomeView() } Tab("Search", systemImage: "magnifyingglass", value: TabType.search) { SearchView() } Tab("Profile", systemImage: "person.crop.circle", value: TabType.profile) { ProfileView() } } .onAppear { windowSizeModel.setWindowSize(for: TabType.home) } .onChange(of: selectedTab) { oldTab, newTab in if oldTab == newTab { return } else if newTab == TabType.home { windowSizeModel.setWindowSize(for: TabType.home) } else if newTab == TabType.search { windowSizeModel.setWindowSize(for: TabType.search) } else if newTab == TabType.profile { windowSizeModel.setWindowSize(for: TabType.profile) } } } }
0
0
32
19h
How Does Update Closure Work in RealityView
I have looked here: Reality View Documentation Found this thread: RealityView Update Closure Thread I am not able to find documentation on how the update closure works. I am loading attachments using reality view's attachment feature (really helpful). I want to remove them programmatically from another file. I found that @State variables can be used. But I am not able to modify them from out side of the ImmersiveView swift file. The second problem I faced was even if I update them inside the file. My debugging statements don't execute. So exactly when does update function run. I know it get's executed at the start (twice for some reason). It also get's executed when I add a window using: openWindow?(id: "ButtonView") I need to use the update closure because I am also not able to get the reference to RealityViewAttachment outside the RealityView struct. My Code(only shown the code necessary. there is other code): @State private var pleaseRefresh = "" @StateObject var model = HandTrackingViewModel() var body: some View { RealityView { content, attachments in if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) { content.add(immersiveContentEntity) } content.add(model.setupContentEntity()) content.add(entityDummy) print("View Loaded") } update: { content, attachments in print("Update Closure Executed") if (model.editWindowAdded) { print("WINDOW ADDED") let theattachment = attachments.entity(for: "sample")! entityDummy.addChild(theattachment) // more code here } } attachments: { Attachment(id: "sample") { Button(action: { model.canEditPos = true model.canRotate = false pleaseRefresh = "changed" }) { HStack { Image(systemName: "pencil.and.outline") .resizable() .scaledToFit() .frame(width: 32, height: 32) Text("Edit Placement") .font(.caption) } .padding(4) } .frame(width: 160, height: 60) } } How can the update method (or the code inside it) run when I want it to? I am new to swift. I apologize if my question seems naive.
1
0
65
13h