swift - 带有表单的 SwiftUI 模态表:设备旋转后左/右填充错误
问题描述
打开包含表单的模式表,然后将设备旋转到横向模式并返回纵向模式时,一切正常。但是,如果模态表在横向模式下打开然后旋转到纵向模式,则左侧和右侧的填充不符合预期。我认为这是 SwiftUI 中的一个错误。有解决方法吗?
struct ContentView: View {
@State var modalDisplayed = false
var body: some View {
Button(action: { self.modalDisplayed = true }) {
Text("Show Modal")
}.sheet(isPresented: $modalDisplayed) {
Form{
Section(header: Text("Section")){
Text("This is a test.")
}
}
}
}
}
如果模态表以横向打开然后旋转为纵向,它的外观:
解决方案
.edgesIgnoringSafeArea(.all)
为我解决了这个问题。(使用 Xcode 11.5 / iOS 13.5)
struct ContentView: View {
@State var modalDisplayed = false
var body: some View {
Button(action: { self.modalDisplayed = true }) {
Text("Show Modal")
}.sheet(isPresented: self.$modalDisplayed) {
Form {
Section(header: Text("Section")){
Text("This is a test.")
}
}
.edgesIgnoringSafeArea(.all)
}
}
}
推荐阅读
- python - 查找二维数组中元素的索引
- python - openpyxl(3.0.3) 保存功能需要很长时间
- javascript - 使用 Python 3.7 选中 HTML 页面中的复选框
- html - 使整个伪元素可点击
- python - 如何避免在 python 3 中重新声明常量
- android - 我在 react-native android 中激活了调试模式,应用程序不再工作,我要回去吗?
- python-2.7 - 如何将自定义参数(如-o)传递给scrapy爬虫
- gradle - 在 Teamcity CI 代理中重用 Gradle 缓存
- blazor - Blazor:如何通过单击按钮提交表单
- nlp - 使用 encode_plus 方法时的标记索引序列长度错误