我在macOS上使用.sheet修饰符以模态方式显示工作表。下面是显示的工作表的视图主体的代码:
var body: some View {
NavigationView {
ZStack {
CloseButton()
patternView
}
}
}
private var patternView: some View {
ScrollView {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 100))],
spacing: 5) {
Button() {
item.pattern = nil
dismiss()
} label: {
Image("no.selection")
.resizable()
.scaledToFit()
.frame(height: StandardSizing.image.height)
}
ForEach(searchResults) { pattern in
Button {
item.pattern = pattern.rawValue
dismiss()
} label: {
Image(pattern.image)
.resizable()
.scaledToFit()
.frame(height: StandardSizing.image.height)
}
}
}.searchable(text: $searchText,
prompt: Text("Pattern"))
.searchScopes($scope) {
Text("All")
.tag(nil as Pattern.PatternType?)
ForEach(Pattern.PatternType.allCases) { type in
Text(type.title)
.tag(type as Pattern.PatternType?)
}
}
}
.padding()
.buttonStyle(.plain)
}
结果:
值得注意的是,在工作表的右侧有一个分隔符,它出现在NavigationView中的换行处。
有人能帮助我理解为什么我看到这个分隔符吗?导航视图是否不适合在macOS上使用?如果不是,我如何使用.searchable修饰符来显示搜索栏?
编辑:使用NaivgationStack而不是NavigationView(折旧)删除了意外的分隔符;但是,搜索栏仍然缺失。
1条答案
按热度按时间enxuqcxy1#
我以前遇到过类似的问题。
您看到的一侧的分隔符可能是默认的列表分隔符样式。LazyVGrid似乎继承了默认的List分隔符样式。
您可以通过将分隔线设置为. nune从LazyVGrid中删除分隔线。