swiftui

Using NavigationLink in Menu (SwiftUI)

本小妞迷上赌 提交于 2021-02-19 02:28:27
问题 Can you use a NavigationLink as a Menu 's item in swiftUI? It seems to do just nothing: Menu { NavigationLink(destination: Text("test1")) { Text("item1") } NavigationLink(destination: Text("test2")) { Text("item2") } } label: { Text("open menu") } In case it is meant to not work as tried above, is there an alternative way of achiving the intended reult? 回答1: NavigationLink should be inside NavigationView hierarchy. The Menu is outside navigation view, so put buttons inside menu which activate

Drag item from one List to another List in SwiftUI

偶尔善良 提交于 2021-02-19 01:52:26
问题 I have two Lists each with simple items. I can rearrange items within a list, with the code shown below. I want to be able to drag an item from one list and drop it into the other list. Not sure what I need to enable to make that happen. As is, I can drag something from one list all over the screen, but I can't drop it anywhere except within its own list; if I release the drag anywhere else, it just flies back to its original location. Clearly, I need to add something(s) to enable the desired

Drag item from one List to another List in SwiftUI

不问归期 提交于 2021-02-19 01:52:08
问题 I have two Lists each with simple items. I can rearrange items within a list, with the code shown below. I want to be able to drag an item from one list and drop it into the other list. Not sure what I need to enable to make that happen. As is, I can drag something from one list all over the screen, but I can't drop it anywhere except within its own list; if I release the drag anywhere else, it just flies back to its original location. Clearly, I need to add something(s) to enable the desired

SwiftUI dismiss keyboard when tapping segmentedControl

こ雲淡風輕ζ 提交于 2021-02-19 01:15:50
问题 I have a TextField in SwiftUI that needs to use a different keyboard depending on the value of a @State variable determined by a SegementedControl() picker. How can I dismiss the keyboard (like send an endEditing event) when the user taps a different segment? I need to do this because I want to change the keyboard type and if the textField is the responder, the keyboard won't change. I have this extension: extension UIApplication { func endEditing() { sendAction(#selector(UIResponder

Navigation Bar hide is not working in SwiftUI

萝らか妹 提交于 2021-02-18 22:53:09
问题 I'm having Three Views. I want to hide the navigation bar in the third View. Even if I give .navigationBarHidden(true) the navigation bar is displaying! I couldn't find where I'm doing wrong. I've attached my code and the resulting screenshot below. Xcode version - 11.1 struct ContentViewOne: View { var body: some View { NavigationView { ZStack { Color.yellow.edgesIgnoringSafeArea(.all) VStack(spacing: 20) { Text("View One") NavigationLink(destination: ContentViewTwo()) { Text("Navigate to

Navigation Bar hide is not working in SwiftUI

对着背影说爱祢 提交于 2021-02-18 22:51:38
问题 I'm having Three Views. I want to hide the navigation bar in the third View. Even if I give .navigationBarHidden(true) the navigation bar is displaying! I couldn't find where I'm doing wrong. I've attached my code and the resulting screenshot below. Xcode version - 11.1 struct ContentViewOne: View { var body: some View { NavigationView { ZStack { Color.yellow.edgesIgnoringSafeArea(.all) VStack(spacing: 20) { Text("View One") NavigationLink(destination: ContentViewTwo()) { Text("Navigate to

SwiftUI Scroll/List Scrolling Events

爱⌒轻易说出口 提交于 2021-02-18 17:21:27
问题 lately I have been trying to create a pull to (refresh, load more) swiftUI Scroll View !!, inspired by https://cocoapods.org/pods/SwiftPullToRefresh I was struggling to get the offset and the size of the content. but now I am struggling to get the event when the user releases the scroll view to finish the UI. here is my current code: struct PullToRefresh2: View { @State var offset : CGPoint = .zero @State var contentSize : CGSize = .zero @State var scrollViewRect : CGRect = .zero @State var

SwiftUI - is it possible to get didSet to fire when changing a @Published struct?

人走茶凉 提交于 2021-02-18 11:23:05
问题 I have just updated to XCode 11.4 and some of my code has stopped working. I have some @Published struct variables in an ObservableObject . Previously, when I updated properties on the struct, the didSet method would fire on the published property, but that's not the case anymore. Is it possible that this behaviour has changed by design in the latest update to Swift? Here's a trivial example: import SwiftUI struct PaddingRect { var left: CGFloat = 20 var right: CGFloat = 20 } final class

Get onAppear behaviour from list in ScrollView in SwiftUI

若如初见. 提交于 2021-02-18 10:31:49
问题 When creating a List view onAppear triggers for elements in that list the way you would expect: As soon as you scroll to that element the onAppear triggers. However, I'm trying to implement a horizontal list like this ScrollView(.horizontal) { HStack(spacing: mySpacing) { ForEach(items) { item in MyView(item: item) .onAppear { \\do something } } } } Using this method the onAppear triggers for all items at once, that is to say: immediately, but I want the same behavior as for a List view. How

SwiftUI @Binding update doesn't refresh view

限于喜欢 提交于 2021-02-18 10:15:14
问题 I feel like I'm missing something very basic, but this example SwiftUI code will not modify the view (despite the Binding updating) when the button is clicked Tutorials I have read suggest this is the correct way to use a binding and the view should refresh automatically import SwiftUI struct ContentView: View { @Binding var isSelected: Bool var body: some View { Button(action: { self.isSelected.toggle() }) { Text(isSelected ? "Selected" : "Not Selected") } } } struct ContentView_Previews: