swiftui

How to specify the type information of an array that would hold SwiftUI custom views

旧巷老猫 提交于 2021-02-04 21:59:29
问题 I am learning SwiftUI and I do understand that to create a view element using SwiftUI framework, your custom type must conform to 'View' protocol. I have a requirement where I want to declare an array which would hold custom SwiftUI components that I would be creating by making a Struct implementing the 'View' protocol. Now I am not sure what to mention as the type of the array since, providing 'View' as the type is giving the compiler error as " Protocol 'View' can only be used as a generic

How to specify the type information of an array that would hold SwiftUI custom views

和自甴很熟 提交于 2021-02-04 21:57:08
问题 I am learning SwiftUI and I do understand that to create a view element using SwiftUI framework, your custom type must conform to 'View' protocol. I have a requirement where I want to declare an array which would hold custom SwiftUI components that I would be creating by making a Struct implementing the 'View' protocol. Now I am not sure what to mention as the type of the array since, providing 'View' as the type is giving the compiler error as " Protocol 'View' can only be used as a generic

SwiftUI: How to change rootview controller programmatically

一世执手 提交于 2021-02-04 21:00:20
问题 I am trying to change the rootview controller to a different screen after the user has logged out. if let window = UIApplication.shared.windows.first { window.rootViewController = UIHostingController(rootView: SignInView()) window.endEditing(true) window.makeKeyAndVisible() } This is what I have so far. It navigates to the different view but it makes the buttons on the new new view unusable. Is there a better way to change the rootview or am I missing something? 回答1: My approach is to create

How do you implement list paging in SwiftUI or infinite list view?

核能气质少年 提交于 2021-02-04 19:42:52
问题 I want help on how to implement infinite list scrolling or paging list in SwiftUI.Thanks in advance 回答1: Your best bet is to use .onAppear and calculate if it's time to fetch your next page. This is a contrived example because typically you're hitting a network or disk which is much slower than this, but it will give you an idea. Tune getNextPageIfNecessary(_:) for your particular use-case. @State var rows: [String] = Array(repeating: "Item", count: 20) var body: some View { List(0..<rows

Extra arguments at positions #11, #12 in call SwiftUI [duplicate]

浪尽此生 提交于 2021-02-04 18:53:46
问题 This question already has answers here : Can't Add More Than 10 Items to View SwiftUI (3 answers) Closed 7 months ago . I keep on getting an "Extra arguments at positions #11, #12 in call" error on my toggle switch in SwiftUI. I've seen other people have the "Extra Arguments in call" error, but the answers didn't seem to help; plus, my error says "positions #11, 12", which I haven't seen happen for others. I am using the Xcode 12 beta if that makes a difference. import SwiftUI let defaults =

How to change the size and position of popover's page in swiftUI?

眉间皱痕 提交于 2021-02-04 17:36:40
问题 I want to set the position and size of Popover page. I tried all parameters of func popover, I think it may be related with attachmentAnchor and arrowEdge. Here is my code: import SwiftUI struct ContentView : View { @State var isPop = false var body: some View { VStack{ Button("Pop", action: {self.isPop = true}) .popover(isPresented: $isPop, attachmentAnchor: .point(UnitPoint(x: 20, y: 20)), arrowEdge: .top, content: {return Rectangle().frame(height: 100).foregroundColor(Color.blue)}) } } }

Is there a SwiftUI equivalent for viewWillDisappear(_:) or detect when a view is about to be removed?

喜夏-厌秋 提交于 2021-02-04 13:03:53
问题 In SwiftUI, I'm trying to find a way to detect that a view is about to be removed only when using the default navigationBackButton . Then perform some action. Using onDisappear(perform:) acts like viewDidDisappear(_:) , and the action performs after another view appears. Or, I was thinking the above problem might be solved by detecting when the default navigationBarBackButton is pressed. But I've found no way to detect that. Is there any solution to perform some action before another view

Add animations to ForEach loop elements (SwiftUI)

↘锁芯ラ 提交于 2021-02-04 11:28:45
问题 Is there any way I can add animation when elements of a ForEach loop appears or disappears? I have tried using withAnimation{} and .animation() in many ways but they didn't seem to work Here is some code (Xcode 11 beta 5): import SwiftUI struct test: View { @State var ContentArray = ["A","B","C"] var body: some View { ScrollView{ VStack{ ForEach(ContentArray.indices, id: \.self){index in ZStack{ // Object Text(self.ContentArray[index]) .frame(width:100,height:100) .background(Color.gray)

Add animations to ForEach loop elements (SwiftUI)

偶尔善良 提交于 2021-02-04 11:28:31
问题 Is there any way I can add animation when elements of a ForEach loop appears or disappears? I have tried using withAnimation{} and .animation() in many ways but they didn't seem to work Here is some code (Xcode 11 beta 5): import SwiftUI struct test: View { @State var ContentArray = ["A","B","C"] var body: some View { ScrollView{ VStack{ ForEach(ContentArray.indices, id: \.self){index in ZStack{ // Object Text(self.ContentArray[index]) .frame(width:100,height:100) .background(Color.gray)

Multiple Bottom sheets - the content doesn't load SwiftUI

二次信任 提交于 2021-02-04 08:20:06
问题 I have made a view with two possible bottom sheets. The action works, and Bottom Sheets do open. Crazy thing is they open without the view inside. I have to close the one I opened and open the other one. When I do and than come back to the first one I will see the content. The code builds without warnings: LogInView - where the logic is: import SwiftUI struct LogInView: View { @EnvironmentObject var userInfo: UserInfo enum Action{ case resetPW, signUp } @State private var showSheet = false