swiftui

SwiftUI inverse animation delay on removal

不问归期 提交于 2021-01-28 05:02:04
问题 I am trying to choreograph animations in SwiftUI. I want two colored bars to move in to the view with a delay between them and then move out of the view with the delays switched so that the removal is the reverse of the insertion. I think I understand why the below code doesn't work, but I can't figure out how to make it do what I need: import SwiftUI struct TestAnimControl: View { @State var show: Bool = false @State var reverseDelay: Bool = false var body: some View { VStack { Button(action

Can @AppStorage be used in the Environment in SwiftUI?

柔情痞子 提交于 2021-01-28 05:00:46
问题 Can @AppStorage be used in the Environment in SwiftUI, if so, how would you do it? I know you can send the value for the @AppStorage from one view to another using @Bindings as a general wondering I would like to know if its possible to put it in the environment. I don't have a practical example as to when this would be applicable, but I was wondering if it was possible. Would this be crazy enough to work? I think you will only store the value and it won't be stored in the UserDefault. struct

Receive the selected TabView from another view - SwiftUI

混江龙づ霸主 提交于 2021-01-28 04:34:46
问题 I'm trying do make a swiftui app with tabView. I want the tabview works normally but also the selected tab may come from the first page The first view struct ContentView: View { @State var selectedTab = 0 var body: some View { VStack{ NavigationView{ VStack(alignment: .center, spacing: 0){ Spacer() NavigationLink(destination: AccueilView(selectedTab: self.$selectedTab)){ VStack{ Image(systemName: "book") Text("Enseignements") } } HStack{ NavigationLink(destination: AccueilView(selectedTab:

Receive the selected TabView from another view - SwiftUI

点点圈 提交于 2021-01-28 04:24:07
问题 I'm trying do make a swiftui app with tabView. I want the tabview works normally but also the selected tab may come from the first page The first view struct ContentView: View { @State var selectedTab = 0 var body: some View { VStack{ NavigationView{ VStack(alignment: .center, spacing: 0){ Spacer() NavigationLink(destination: AccueilView(selectedTab: self.$selectedTab)){ VStack{ Image(systemName: "book") Text("Enseignements") } } HStack{ NavigationLink(destination: AccueilView(selectedTab:

Why pop to root does not work in this sample code SwiftUI?

倖福魔咒の 提交于 2021-01-28 04:10:45
问题 For the purpose of this question, I have provided minimum sample code to re-create the bug. Just copy/paste it to run. import SwiftUI final class Popper: ObservableObject { @Published var shouldProceed: String? = nil var id: String init(id: String) { self.id = id } } struct ContentView: View { @StateObject var popper = Popper(id: "ROOT") var body: some View { NavigationView { VStack(spacing: 40) { Text("You are now in ROOT").font(.largeTitle) Text("Tap Here to goto V1").onTapGesture { popper

Fetch Contact Image - SwiftUI

ぃ、小莉子 提交于 2021-01-28 04:05:07
问题 I'm trying to fetch the image property of a given contact . Here's what I got: Model struct Contact: Identifiable { let contact: CNContact var id: String { contact.identifier } var image: Data? { contact.imageData } var givenName: String { contact.givenName } } static func fetch(_ completion: @escaping(Result<[Contact], Error>) -> Void) { let containerID = CNContactStore().defaultContainerIdentifier let predicate = CNContact.predicateForContactsInContainer(withIdentifier: containerID()) let

SwiftUI EnvironmentObject not available in View initializer?

前提是你 提交于 2021-01-28 03:06:48
问题 I passed the environmentObject appSettings into my view successfully. I can use it to modify my font and the picker in my View. But if I try to access an environmentObject published variable in the view init() it crashes with: Thread 1: Fatal error: No ObservableObject of type AppSettings found. A View.environmentObject(_:) for AppSettings may be missing as an ancestor of this view. Are there special rules about using an environmentObject in a custom SwiftUI View initializer? Here's the start

SwiftUI Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift

一世执手 提交于 2021-01-28 02:13:03
问题 I have a environment object that is an array, and a panel in my settings page where the user can add/remove values to the array...here is the list of items in the array displayed visually for the user: ScrollView { VStack { ForEach(self.env.numbers.indices, id: \.self) { number in ZStack { HStack { Text("#\(number + 1): ") .font(Font.custom(K.font.montserratMedium, size: 17.0)) .foregroundColor(Color(K.SettingsTextColor)) // Spacer() NumberTextField(self.env.numbers[number], text: self.$env

What's the purpose of .environmentObject() view operator vs @EnvironmentObject?

拈花ヽ惹草 提交于 2021-01-28 02:07:38
问题 I'm attempting to crawl out of the proverbial Neophyte abyss here. I'm beginning to grasp the use of @EnvironmentObject till I notice the .environmentObject() view operator in the docs. Here's my code: import SwiftUI struct SecondarySwiftUI: View { @EnvironmentObject var settings: Settings var body: some View { ZStack { Color.red Text("Chosen One: \(settings.pickerSelection.name)") }.environmentObject(settings) //...doesn't appear to be of use. } func doSomething() {} } I tried to replace the

Navigation Link in bar Items goes back to top of NavigationView

核能气质少年 提交于 2021-01-28 01:57:23
问题 struct Testing: View { var body: some View { NavigationView{ VStack { Text("View 1") Text("View 1.3") NavigationLink(destination: TestView(), label: { Text("View 1 navigation") }) } } } } struct TestView: View { var body: some View { VStack { Text("View 2") } .navigationBarItems(trailing:NavigationLink( destination: Text("View 3"), label: { Text("Navigate") })) } } When clicking the NavigationLink inside of TestViews navigationBarItems it navigates to View 3. When I click the back button it