Post

Replies

Boosts

Views

Activity

Reply to SpatialTapGesture and collision surface's normal?
Yes, simd_float4x4 is correct. I know that AR-related functions defined by Apple, return a simd_float4x4 type that includes not only the x, y, and z axes, but also other information such as angles. So you need to extract the desired information value from the simd_float4x4 array and use it. This answer is not absolute and is just my opinion. When I was developing AR App, I could only find the above method.
Topic: Spatial Computing SubTopic: ARKit Tags:
Mar ’24
Reply to Add Close button in FamilyActivityPicker Toolbar
How about using the code below? var body: some View { NavigationStack { FamilyActivityPicker() .toolbar { ToolbarItem(placement: .topBarTrailing) { closeButton } } } } @Environment(\.dismiss) var dismiss private var closeButton: some View { Button { dismiss() } label: { Image(systemName: "xmark") .foregroundStyle(.white) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to View Update Failure
I also experienced a similar problem in the past. How about trying this way? class SaveWords: ObservableObject { static let shared = SaveWords() // others... } import SwiftUI struct SearchView: View { @State private var searchText = "" var save = SaveWords.shared @State var heart: String? @State var disappear = false @State var done = true var body: some View { NavigationView { VStack { if !disappear { SearchBarView(text: $searchText) Spacer() } if searchText != "" { List(.constant(Array(FetchWord.getWordFromStart(start: searchText)).prefix(10).map {Word(word: $0.1)})) { suggestion in NavigationLink(destination: suggestion.IPA.wrappedValue == "error" ? AnyView(EmptyView()) : AnyView(PracticeView(wordSheet: suggestion) .onAppear { disappear = true if done { SaveWords.file = "Favorites" DispatchQueue.main.async { Task { try? await save.load() heart = save.words.contains(suggestion.wrappedValue) ? ".fill" : "" } } } } .onDisappear { disappear = false Task { SaveWords.file = "History" try? await save.load() if save.words.first != suggestion.wrappedValue { save.words.insert(suggestion.wrappedValue, at: 0) try? await save.save() } } } .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button(action: { SaveWords.file = "Favorites" done = false if heart == "" { heart = ".fill" DispatchQueue.main.async { Task { try? await save.load() if !save.words.contains(suggestion.wrappedValue) { save.words.insert(suggestion.wrappedValue, at: 0) try? await save.save() } } } } else { heart = "" DispatchQueue.main.async { Task { try? await save.load() try? await save.delete(wordToDelete: suggestion.wrappedValue) try? await save.save() } } } done = true }, label: { Image(systemName: "heart" + (heart ?? "")) }) } }) ) { if suggestion.IPA.wrappedValue != "error" { CardView(wordSheet: suggestion) } } } } } Spacer() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to Reality Kit on Swift Playgrounds
Use the code below. (If the Reality Kit File is large, I recommend using the loadModelAsync function.) If your Reality Kit file is a usdz file, try using loadModel instead of loadAnchor. Hope this helps. func makeUIView(context: Context) -> ARView { let arView = ARView(frame: .zero) // Create a cube model let model = try? Entity.loadAnchor(named: "RealityKitFilename") // Create horizontal plane anchor for the content let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2))) if let model = model { anchor.children.append(model) // Add the horizontal plane anchor to the scene arView.scene.anchors.append(anchor) } return arView }
Feb ’24
Reply to SwiftUI Sheet race condition
I think this problem appears because Optional unwrapping is not done. (If you check the actual printed value, the value is properly assigned to Optional(1)) How about modifying the code like below? import SwiftUI struct ContentView: View { @State var myVar: Int? @State private var presentSheet: Bool = false var body: some View { VStack { // Uncommenting the following Text() view will "fix" the bug (kind of, see a better workaround below). // Text("The value is \(myVar == nil ? "nil" : "not nil")") Button { myVar = nil } label: { Text("Set value to nil.") } Button { myVar = 1 presentSheet.toggle() } label: { Text("Set value to 1 and open sheet.") } } .sheet(isPresented: $presentSheet, content: { if let myVar = myVar { Text("The value is nil") .onAppear { print(myVar) // prints Optional(1) } } else { Text("The value is not nil") } }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24