swiftui

SwiftUI overlay blocking List scroll events

青春壹個敷衍的年華 提交于 2021-01-27 13:18:49
问题 I'd like to put a semi-transparent image overlay on top of the list in SwiftUI. I've tried the code like this: struct ContentView: View { var body: some View { List { Text("first") Text("second") Text("third") } .overlay( Image(systemName: "hifispeaker") .resizable() .frame(width: 200, height: 200) .opacity(0.15) ) } } It looks as expected, but if you place your finger within image boundaries the scrolling of the list doesn't work (if you try to scroll outside the image it works fine) I've

How do you preview a view containing a binding to its parent view's state?

百般思念 提交于 2021-01-27 13:10:31
问题 I present this view as a sheet from its parent view struct NamesView: View { @Binding var match: Match var body: some View { ... } } Since the match source of truth is in the parent view presenting this NamesView sheet, when the view is constructed I pass in a $match binding and data flows as intended. However, when constructing this view in a preview provider struct NamesView_Previews: PreviewProvider { static var previews: some View { NamesView() } } the compiler says that NamesView()

With SwiftUI, is there a way to constrain a view's size to another non-sibling view?

妖精的绣舞 提交于 2021-01-27 13:09:59
问题 I'm fiddling with a view layout - a graph - where I'm seeing how far I can get within an all-SwiftUI layout. Each of the component pieces are fine, but assembling the whole isn't working quite as I'd like. What I've found is that I can easily constrain sizing along a single stack axis - but not two axis at once (both vertical and horizontal). I started to reach for AlignmentGuides, as I found you can align non-siblings with a custom guide. That will help my goal, but it doesn't solve the

Swiftui - only show a percentage of a view

流过昼夜 提交于 2021-01-27 12:30:11
问题 I have a RoundedRectangle , and my objective is to lay another RoundedRectangle over it such that the overlay shows a "percentage complete". I can't seem to find the proper incantation to do so, though. I think that ideally, the overlay should somehow only show a percentage of itself. Resizing itself to match the percentage skews the shape of the overlay. import PlaygroundSupport struct ContentView: View { @State private var value: Double = 0 var body: some View { GeometryReader { geom in

How can my selection go right in the list I created in SwiftUI

纵然是瞬间 提交于 2021-01-27 12:29:55
问题 I created the list showing the array of digits. When you select multiple digits and hit the button below, it should tell you the sum of the selected digits. However, when you select the same digits in the different rows, both of them get checked at a time. I understand that this should be fixed by using UUID, but the final result that I want is the sum of the digits, which is Int. Therefore, I have been lost... Can someone tell me how to make it right, please? Also, the last row doesn't get

How to put View on top of all other views in SwiftUI

我的梦境 提交于 2021-01-27 12:16:24
问题 I'm developing SwiftUI test app and I added my custom DropDown menu here. All works fine except dropdown menu is below other views. So users can't see & click dropdown menu correctly. Here's my dropdown menu. import SwiftUI var dropdownCornerRadius:CGFloat = 3.0 struct DropdownOption: Hashable { public static func == (lhs: DropdownOption, rhs: DropdownOption) -> Bool { return lhs.key == rhs.key } var key: String var val: String } struct DropdownOptionElement: View { var dropdownWidth:CGFloat

How to set button focus in SwiftUI?

白昼怎懂夜的黑 提交于 2021-01-27 08:17:47
问题 !!! TVOS !!! I have list of buttons and it somehow autofocus first button in that list (when view is loaded). Is there any way how to focus another button in that list using SwiftUI ? I know there is preferredFocusedView in UIKit but id like to do this in SwiftUI . Thanks for any advice! 回答1: SwiftUI 2.0 Note: !! Partial solution !! The following approach, as tested with Xcode 12b5 / tvOS 14 works only with stacks and does not work (in any tested combination) for List/ScrollView. Anyway for

How to set button focus in SwiftUI?

五迷三道 提交于 2021-01-27 08:16:27
问题 !!! TVOS !!! I have list of buttons and it somehow autofocus first button in that list (when view is loaded). Is there any way how to focus another button in that list using SwiftUI ? I know there is preferredFocusedView in UIKit but id like to do this in SwiftUI . Thanks for any advice! 回答1: SwiftUI 2.0 Note: !! Partial solution !! The following approach, as tested with Xcode 12b5 / tvOS 14 works only with stacks and does not work (in any tested combination) for List/ScrollView. Anyway for

Programmatically change to another tab in SwiftUI

折月煮酒 提交于 2021-01-27 07:58:51
问题 I'm trying to implement in SwiftUI where you press a button in a view on one tab, it changes to another tab. I would do with UIKit: if [condition...button pressed] { self.tabBarController!.selectedIndex = 2 } But is there an equivalent way to achieve this in SwiftUI? 回答1: You just need to update a @State variable responsible for the selection. But if you want to do it from a child View you can pass it as a @Binding variable: struct ContentView: View { @State private var tabSelection = 1 var

Programmatically change to another tab in SwiftUI

左心房为你撑大大i 提交于 2021-01-27 07:54:04
问题 I'm trying to implement in SwiftUI where you press a button in a view on one tab, it changes to another tab. I would do with UIKit: if [condition...button pressed] { self.tabBarController!.selectedIndex = 2 } But is there an equivalent way to achieve this in SwiftUI? 回答1: You just need to update a @State variable responsible for the selection. But if you want to do it from a child View you can pass it as a @Binding variable: struct ContentView: View { @State private var tabSelection = 1 var