SWIFTUI 我有一个选择器视图(轮式),我将其框架剪裁()到屏幕的一半宽度,从 UI 中您可以看到它的一半,但可滚动区域在该框架之外仍然可操作。如何删除该外部区域以使其不可滚动?
HStack(spacing: 0) {
Picker(selection: self.$viewModel.selectedFrameworkIndex, label: Text("")) {
ForEach(0 ..< viewModel.Categories.count) {
Text(self.viewModel.Categories[$0])
.foregroundColor((self.colorScheme == .dark) ? Color.white : Color.black)
}
}
.frame(width: width / 2) // width is width of my screen
.clipped()
}
Run Code Online (Sandbox Code Playgroud)
在 .clipped() 之后添加 .compositingGroup()
HStack(spacing: 0) {
Picker(selection: self.$viewModel.selectedFrameworkIndex, label: Text("")) {
ForEach(0 ..< viewModel.Categories.count) {
Text(self.viewModel.Categories[$0])
.foregroundColor((self.colorScheme == .dark) ? Color.white : Color.black)
}
}
.frame(width: width / 2) // width is width of my screen
.clipped()
.compositingGroup() }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1515 次 |
最近记录: |