我正在开发一个基于具有三个 TabItem 的 Tabview 的应用程序。每个 TabItem 都是一个列表,我将能够在这些列表上显示一种模态视图。当我无法将工作表称为模态视图时,问题就出现了,因为工作表几乎是全窗口的。我需要某种底部模态视图,因此我创建了一个 View ,将其呈现在具有较高 ZIndex 的列表上。它似乎一直有效,直到您单击选项卡栏并选择另一个部署了“模态” View 的 TabItem。错误是:
[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes.
所以,我想作为解决方案将可点击区域限制为“模态” View 区域。有没有办法实现这个目标?
最佳答案
可能您有一些条件状态,具体取决于您呈现的“类似模态” View ,因此根据相同的条件,您可以在 TabView 下方禁用,如下所示
TabView {
// ... tabs content here
}.disabled(showingModal)
更新:这是我所说的方法演示(使用 Xcode 11.3+ 进行测试)
struct TestTabViewModal: View {
@State private var selectedTab = 0
@State private var modalShown = false
var body: some View {
ZStack {
TabView(selection: $selectedTab) {
VStack {
Button("Show Modal") { self.modalShown = true }
.padding(.top, 40)
Spacer()
}
.tabItem {
Image(systemName: "1.circle")
}.tag(0)
Text("2").tabItem {
Image(systemName: "1.circle")
}.tag(1)
}.disabled(modalShown)
if modalShown {
RoundedRectangle(cornerRadius: 10)
.fill(Color.yellow)
.frame(width: 320, height: 240)
.overlay(Button("CloseMe") { self.modalShown = false })
}
}
}
}
关于ios - SwiftUI:在主视图上呈现模态(实际上不是模态) View 时,如何限制 View 的可点击区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60110031/