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

查看:138
本文介绍了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上运行的相同代码,发现问题是GeometryProxy结构未在iOS 14.0中初始化.

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()
    }
  }
}

推荐答案

肯定已更改-这篇文章进行了总结:

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天全站免登陆