swiftui

SwiftUI iOS14 GeometryReader Invalid frame dimension

这一生的挚爱 提交于 2020-12-13 18:55:21
问题 My GeometryReader was working fine in iOS13 but now in iOS14 i get a thread issue. "Invalid frame dimension (negative or non-finite)." I printed the size that the reader should give back and it looked fine. The app is still basically working, but looks a bit weird, because there is some padding introduced. Does anyone have any ideas how to tackle this? 来源: https://stackoverflow.com/questions/64027041/swiftui-ios14-geometryreader-invalid-frame-dimension

List inside ScrollView is not displayed on WatchOs

非 Y 不嫁゛ 提交于 2020-12-13 05:03:10
问题 I have a list inside a scrollview and it is not displaying below the image and the buttons. I've also tried to put the list and other items inside of a VStack and that allows me to see one item of the list at the time opposed to scrolling past the Image and buttons to show the whole list. ScrollView{ Image(uiImage: self.image) .resizable() .frame(width: 80, height: 80) .scaledToFit() Text("\(name)") .lineLimit(2) HStack{ Button(action: { print("button1") }){ Image(systemName: "pencil") }

SwiftUI List not getting updated when `listRowInsets` are applied

大憨熊 提交于 2020-12-13 04:32:01
问题 Goal Update data in a List on tap Problem When .listRowInsets are applied to the list rows, the list stops getting updates when the state changes. Code struct ContentView: View { private var array = ["a", "b", "c"] @State private var selectedIndex = 0 var body: some View { makeBody() } private func makeRow(_ t: String, index: Int) -> some View { return HStack { Text(t) Spacer() if selectedIndex == index { Image(systemName: "checkmark.circle") } } .contentShape(Rectangle()) .onTapGesture {

Can you specify a “Where” in a SwiftUI ForEach statement?

霸气de小男生 提交于 2020-12-13 03:35:41
问题 In a SwiftUI application, I have a large class defining data. In part of the app, I would like to look at one record where the ID matches what I am looking for. I have done it as follows, but there seems it should be more straight forward. Such as allowing a where clause. Any ideas? ForEach (ItemList) { item in if (item.itemId = thisId) { Text(item.description) } } So rather than going thru the entire list to find the match, I'd like to: ForEach (ItemList WHERE ID = XXX) { OR (more preferably

Update progress value from fileImporter modifier in SwiftUI

送分小仙女□ 提交于 2020-12-13 03:30:41
问题 I have a progress bar with its value updated while processing a file using the fileImporter modifier. I am not sure why the progress bar is not updated as the file is being processed (is it because it is part of the closure?). Below is how I am implementing the progress bar. Any help is greatly appreciated! the ContentView basically has a button that triggers the processing of the selected file using a button and the .fileImporter modifier in a closure. struct ContentView: View {

SwiftUI | DragGestures onEnded never called if canceled by ScrollView

不想你离开。 提交于 2020-12-13 03:09:17
问题 I have the following problem. I have a View inside a ScrollView that I want to drag. Now, everything works fine, the dragging occurs and the scrolling as well. But once I try to do both, the dragOffset appears to stay, instead of resetting to its initial position. More so, onEnded of the DragGesture never happens. How can I stop this from happening and reset the green Rectangle to its initial position? Visual representation Dragging or scrolling works just fine. But whenever I do both, this

SwiftUI | DragGestures onEnded never called if canceled by ScrollView

拈花ヽ惹草 提交于 2020-12-13 03:05:37
问题 I have the following problem. I have a View inside a ScrollView that I want to drag. Now, everything works fine, the dragging occurs and the scrolling as well. But once I try to do both, the dragOffset appears to stay, instead of resetting to its initial position. More so, onEnded of the DragGesture never happens. How can I stop this from happening and reset the green Rectangle to its initial position? Visual representation Dragging or scrolling works just fine. But whenever I do both, this

SwiftUI - List editing mode - how to change delete button title?

人走茶凉 提交于 2020-12-13 02:59:38
问题 Is there a way to change the delete button title when editing a List? Example - struct ContentView: View { @State private var users = ["Paul", "Taylor", "Adele"] var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) }.onDelete(perform: delete) }.navigationBarItems(trailing: EditButton()) } } func delete(source: IndexSet) { } } 回答1: As of Xcode 11.3.1, SwiftUI doesn't support custom swipe actions for List items. Based on the history of Apple’s SDK

SwiftUI - List editing mode - how to change delete button title?

余生长醉 提交于 2020-12-13 02:58:27
问题 Is there a way to change the delete button title when editing a List? Example - struct ContentView: View { @State private var users = ["Paul", "Taylor", "Adele"] var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) }.onDelete(perform: delete) }.navigationBarItems(trailing: EditButton()) } } func delete(source: IndexSet) { } } 回答1: As of Xcode 11.3.1, SwiftUI doesn't support custom swipe actions for List items. Based on the history of Apple’s SDK

Combine onChange and onAppear events in SwiftUI view?

白昼怎懂夜的黑 提交于 2020-12-13 02:57:10
问题 I'm observe a property on a view using the onChange modifier. However, I'd also like the same piece of code to run on the initial value as well because sometimes the data is injected in the initializer or asynchronously loaded later. For example, I have a view that gets a model injected. Sometimes this model has data in it to begin with (like previews), or is asynchronously retrieved from the network. class MyModel: ObservableObject { @Published var counter = 0 } struct ContentView: View {