swiftui

SwiftUI grid with column that fits content?

安稳与你 提交于 2021-01-28 17:02:33
问题 Is this layout possible with SwiftUI? I want the first column to wrap the size of the labels, so in this case it will be just big enough to show "Bigger Label:". Then give the rest of the space to the second column. This layout is pretty simple with auto layout. SwiftUI 2020 has LazyVGrid but the only ways I see to set the column sizes use hardcoded numbers. Do they not understand what a problem causes with multiple languages and user-adjustable font sizes? 回答1: It is not so complex if to

Delay a repeating animation in SwiftUI with between full autoreverse repeat cycles

牧云@^-^@ 提交于 2021-01-28 14:25:50
问题 I’m building an Apple Watch app in SwiftUI that reads the user’s heart rate and displays it next to a heart symbol. I have an animation that makes the heart symbol beat repeatedly. Since I know the actual user’s heart rate, I’d like to make it beat at the same rate as the user’s heart rate, updating the animation every time the rate changes. I can determine how long many seconds should be between beats by dividing the heart rate by 60. For example, if the user’s heart rate is 80 BPM, the

How do you use enumerated in a list of structs in ForEach Swiftui?

試著忘記壹切 提交于 2021-01-28 14:02:09
问题 I wish to utilise the index from the items in ForEach. This is regarding the post I made here where I have now changed the buttonTitles into a list of struct from a dictionary. However I can't seem to do the usual .enumerated() method in ForEach with [struct]. struct ButtonObject: Hashable{ let id = UUID() var name: String var isSelected: Bool } class SomeData: ObservableObject{ @Published var buttonObjects: [ButtonObject] = [ButtonObject(name: "tag1", isSelected: false), ButtonObject(name:

Using GeometryReader with ScrollView

て烟熏妆下的殇ゞ 提交于 2021-01-28 13:50:03
问题 I'm trying to use GeometryReader to assign a maxHeight to a list in a Scrollview . For the purpose of this question, I created the following project : GeometryReaderTesting. It sets up a ContentView with a : - Text. - List. - Text. I extracted the List and last Text into their own view, using @ViewBuilder and I want to set the maxHeight of the List to .5 the height of my user's screen. The problem is that the app won't build with the following errors, and the GeometryReader doesn't seem to be

SwiftUI ForEach refresh makes view pop

只愿长相守 提交于 2021-01-28 13:34:18
问题 I have something like this: import SwiftUI struct Overview: View { @ObservedObject var firstArray = FirstArray() var body: some View { Group{ ScrollView(){ ForEach(self.firstArray.array, id: \.self){ array in SubView(array: array) } Spacer() } }.navigationBarTitle("Overview") } } struct SubView: View { @State var array var body: some View { NavigationLink(destination: DetailInfo(array: array){ Image(systemName: "pencil.circle").resizable().frame(width: 30, height: 30) } }.navigationBarTitle(

SwiftUI: EditButton does not trigger onDelete when embedded within an HStack Section header

て烟熏妆下的殇ゞ 提交于 2021-01-28 13:33:29
问题 I have a Form Section which I want to show some text and the EditButton() within the same header line as shown below: The issue occurs when I tap the button whenever its embedded within an HStack. The button text toggles between "Edit" and "Done", yet it doesn't call the onDelete() action for the rows. However, it does work if it's solely assigned as the header, footer, or embedded in a Group arrangement for the Section. Section(header: HStack { Text("Recent"); Spacer(); EditButton() }) {

SwiftUI 2 Firebase push notification

人盡茶涼 提交于 2021-01-28 13:30:33
问题 So, I am building iOS app with SwiftUI 2 and new Application life cycle, trying to implement AppsDelegate and Firebase push notification here my codes sample import SwiftUI @main struct App: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate var body: some Scene { WindowGroup { ContentView().environmentObject(AppSettings()) } } } and AppDelegate import Firebase import FirebaseMessaging import UserNotifications import Foundation import UIKit class AppDelegate: NSObject { let

How to get at a value in a coordinator class of a UIRepresentable?

好久不见. 提交于 2021-01-28 12:54:18
问题 I am using the charts package to display the elevation, when I tap the chart I get the index of the point and I want to use that index to place a marker on the map above it. I.e locations[index].coordinate. I have the following code and I am trying to pass the index value to my mapView that is also using UIRepresentable to display the map, but I'm having a hard time figuring out how to connect to the publisher. How do I connect the @Published in the Coordinator class to the MapKitView, so

How to get at a value in a coordinator class of a UIRepresentable?

六眼飞鱼酱① 提交于 2021-01-28 12:52:45
问题 I am using the charts package to display the elevation, when I tap the chart I get the index of the point and I want to use that index to place a marker on the map above it. I.e locations[index].coordinate. I have the following code and I am trying to pass the index value to my mapView that is also using UIRepresentable to display the map, but I'm having a hard time figuring out how to connect to the publisher. How do I connect the @Published in the Coordinator class to the MapKitView, so

How to get at a value in a coordinator class of a UIRepresentable?

吃可爱长大的小学妹 提交于 2021-01-28 12:51:52
问题 I am using the charts package to display the elevation, when I tap the chart I get the index of the point and I want to use that index to place a marker on the map above it. I.e locations[index].coordinate. I have the following code and I am trying to pass the index value to my mapView that is also using UIRepresentable to display the map, but I'm having a hard time figuring out how to connect to the publisher. How do I connect the @Published in the Coordinator class to the MapKitView, so