模态选择器没有向右滚动 SwiftUI [英] Modal picker not scrolling right SwiftUI
问题描述
我创建了一个模态,但它似乎在选择上有一个错误.向左滚动时,它向右滚动,我必须到左边的边缘才能滚动,这是它的外观:
I created a modal but it seems to have a bug on the selection. When scrolling the left, it scrolls the right, I have to go to the very edge of the left to be able to scroll, this is how it looks:
import SwiftUI
struct ContentView: View {
@State var showingModal = false
@State var hours: Int = 0
@State var minutes: Int = 0
var body: some View {
ZStack {
VStack {
Button("Show me"){
self.showingModal = true
}
if $showingModal.wrappedValue {
VStack(alignment: .center) {
ZStack{
Color.black.opacity(0.4)
.edgesIgnoringSafeArea(.vertical)
// this one is it
VStack(spacing: 20) {
Text("Time between meals")
.bold().padding()
.frame(maxWidth: .infinity)
.background(Color.yellow)
.foregroundColor(Color.white)
HStack {
Spacer()
VStack {
Picker("", selection: $hours){
ForEach(0..<4, id: \.self) { i in
Text("\(i) hours").tag(i)
}
}
.frame(width: 150, height: 120)
.clipped()
}
VStack {
Picker("", selection: $minutes){
ForEach(0..<60, id: \.self) { i in
Text("\(i) min").tag(i)
}
}
.frame(width: 150, height: 120)
.clipped()
}
}
Spacer()
Button(action: {
self.showingModal = false
}){
Text("Close")
} .padding()
}
.frame(width:300, height: 300)
.background(Color.white)
.cornerRadius(20).shadow(radius: 20)
}
}
}
}
}
}
}
我该如何修复那个小错误?我尝试使用布局但没有用...任何帮助将不胜感激
How can I fix that little bug? I tried playing around with the layout but no use... any help would be appreciated
推荐答案
如果我告诉你你的 Picker 不工作的原因是这条线怎么办?
What if I told you the reason your Picker not working was this line?
.cornerRadius(20).shadow(radius: 20)
不幸的是,SwiftUI 仍然有很多问题,有时它没有做它应该做的事情,尤其是 Pickers 不是那么可靠.我想我们需要等待 SwiftUI 的下一次迭代,但现在您可以用下面的代码替换该行:
Unfortunately, SwiftUI is still quite buggy and sometimes it doesn't do what it is supposed to do and especially Pickers are not that reliable. I guess we'll need to wait and see the next iteration of SwiftUI, but for now you can replace that line with the code below:
.mask(RoundedRectangle(cornerRadius: 20))
.shadow(radius: 20)
这篇关于模态选择器没有向右滚动 SwiftUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!