iOS 14 已更改(或损坏?)SwiftUI GeometryReader [英] iOS 14 has Changed (or broken?) SwiftUI GeometryReader

查看:19
本文介绍了iOS 14 已更改(或损坏?)SwiftUI GeometryReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从今天发布的 iOS 14.0 开始,我的 iOS 代码(严重依赖 GeometryReader 进行布局)不再运行良好.也就是说,布局有点随机.

As of today's release of iOS 14.0 my iOS code, which depends heavily on GeometryReader for layout, is no longer working well. I.e, layout has been kind of randomized.

在 Xcode 调试器中,我比较了在 iOS 13.6 和 iOS 14.0 上运行的相同代码,发现问题在于 iOS 14.0 中未初始化 GeometryProxy 结构.

In the Xcode debugger I have compared the same code running on iOS 13.6 vs iOS 14.0 and see that the problem is that the GeometryProxy structure is not being initialized in iOS 14.0.

在变量 g 下方的示例代码中,GeometryProxy 在 iOS 13 中具有有效的宽度和高度值,但在 iOS 14 中全为零.(这只是我对 GeometryProxy 值进行的更简单的使用之一——我会如果没有人指出这个片段可以通过其他方式更容易地完成的明显事实,我们将不胜感激.)

In the example code below the variable g, a GeometryProxy, has valid width and height values in iOS 13 but is all zero's in iOS 14. (This is just one of the simpler uses I make of GeometryProxy values -- I would appreciate if nobody points out the obvious fact that this snippet could be accomplished much more easily in another way.)

这是对 GeometryReader 的更改还是错误?有人有解决方法吗?我是否在依赖 GeometryReader 进行动态布局时犯了一个巨大的错误?

Is this a change to the GeometryReader or a bug? Anyone have a workaround? Did I make a huge mistake depending on GeometryReader for dynamic layout?

struct TextView: View {
  @EnvironmentObject var data: RecorderData
  let m = MusicalNote()

  var body: some View {
      GeometryReader { g in
          Stack(alignment: .leading) {
              Text(self.data.curNote.getString())
                 .font(.system(size: g.size.height / 2.4))
                 .padding(.bottom)
              Text(self.data.fdata.fingerings[self.data.curRecorder.id] ![self.data.curNote.seq] ![self.data.curFingType] ![self.data.currentFingeringChoice].comment)
                 .font(.headline)
        }
      Spacer()
    }
  }
}

推荐答案

确实发生了变化 - 这篇文章总结了它:https://swiftui-lab.com/geometryreader-bug/

It's definitely changed - this post sums it up: https://swiftui-lab.com/geometryreader-bug/

GeometryReader 现在的内容布局与过去不同.它曾经在父级中水平和垂直居中,但现在将其与左上角对齐.

GeometryReader now lays out its content different to how it used to. It used to centre it horizontally and vertically in the parent but now it aligns it to the top-left.

我的应用程序看起来很糟糕 - 令人沮丧的是,不清楚这是新行为还是设计的那样,或者它是否是一个错误并将被修复.我正在尝试检查我的应用程序并手动应用偏移量,但使用 GeometryReader 的布局的动态特性意味着它并不总是那么容易.

My app looks awful - what's frustrating is it's not clear if this is new behaviour and is as-designed, or whether it's a bug and will be fixed. I'm trying to go through my app and manually apply offsets but the dynamic nature of layouts using GeometryReader means it is not always easy.

这篇关于iOS 14 已更改(或损坏?)SwiftUI GeometryReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆