【问题标题】:UI not filling up entire screen. Black bars on top and bottom [duplicate]UI 没有填满整个屏幕。顶部和底部的黑条[重复]
【发布时间】:2021-05-27 13:08:20
【问题描述】:

我的 SwiftUI 界面没有填满整个屏幕。

它应该是这样的:

这是它在设备上的实际外观:

这是我的内容视图:

ContentView.swift

struct ContentView : View {
    var body: some View {
        ZStack(content: {
            Circle().fill(ColorManager.petSupportBlue).frame(width: 350, height: 350).position(x: -50, y:30).ignoresSafeArea()
            Circle().fill(ColorManager.petSupportBlue).frame(width: 350, height: 350).position(x: 50, y: -50).ignoresSafeArea()
        })
    }
}

【问题讨论】:

标签: ios swiftui


【解决方案1】:

如下使用

var body: some View {
    ZStack(content: {
        Circle().fill(ColorManager.petSupportBlue).frame(width: 350, height: 350).position(x: -50, y:30).ignoresSafeArea()
        Circle().fill(ColorManager.petSupportBlue).frame(width: 350, height: 350).position(x: 50, y: -50).ignoresSafeArea()
    })
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .ignoresSafeArea()
}

【讨论】:

  • 顶部和底部的黑条显示方式相同
  • @DayemSaeed,使用 Xcode 12.4 / iOS 14.4 测试 - 工作正常。您使用哪个环境?这和你测试的代码一样吗?
  • 是的。通过添加启动屏幕解决了我的问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-01
  • 2016-12-08
  • 2019-05-07
  • 2019-10-26
  • 2022-11-26
  • 2015-11-25
  • 1970-01-01
相关资源
最近更新 更多