swift - .edgesIgnoringSafeArea 无法正常工作
问题描述
我的 ContentView 中有一个 NavigationLink,它显示了带有一些文本的 SecondView。当我在 SecondView 中应用 .edgesIgnoringSafeArea 修饰符时,文本会超出屏幕,并且只有在 NavigationBar 隐藏时才会在 NavigationLink 中发生这种情况。
如果您也遇到这种情况,您也可以测试此代码吗?
struct ContentView: View {
@State var hiddenBar = false
var body: some View {
NavigationView {
NavigationLink(destination: SecondView(hiddenBar: $hiddenBar)) {
Text("Go to second View")
}
.onAppear {
self.hiddenBar = false
}
.navigationBarTitle("Title", displayMode: .inline)
.navigationBarHidden(hiddenBar)
}
}
}
struct SecondView: View {
@Binding var hiddenBar: Bool
var body: some View {
VStack {
Text("Text that goes outside of the safe area plus the amount of Navigation Bar height because it's hidden...You can see just this peace of text here")
Spacer()
}
.onAppear {
self.hiddenBar = true
}
.edgesIgnoringSafeArea(.top)
}
}
解决方案
推荐阅读
- dataframe - 如何将 DBI ODBC SQL 查询下载到文件
- c# - 实现没有饥饿的while循环以在wpf中重绘图像
- generics - 实现 BaseDao 的多个 Daos 的存储库类委托 - 可能吗?
- android - 如何在我的 DAO 中引用可搜索的 FTS4 表而不会出现编译器错误?
- c# - 相对 URI 字符串不针对格式“uri”进行验证
- java - 如何在处理中的不同时间间隔后触发不同的事件?
- node.js - 错误在运行应用程序时无法解析模块@angular/core 错误
- arrays - 如何根据字母/符号/数字对字符串数组进行排序
- wordpress - 如何在 post.php 上获取作者 ID?$authordata 返回 NULL (Wordpress)
- json - 在 postgresql 查询中展平 jsonb 对象的更好方法是什么