Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

ios - Two Implementations of Geometry Reader, but one isn't working

Why does

    GeometryReader { geometry in body(for: geometry.size)

work. But this doesn't?

    GeometryReader(content: { (geometry: GeometryProxy) -> Content in body(for: geometry.size)})

I get this error: Cannot find type 'Content' in scope

It's strange because aren't these identical? The difference is we get rid of the types because of type inference and the content label because that's inferred too.

Moreover, why does geometry contain so much information like size, etc? I'm not too familiar with geometryproxy and so I'll need to do more reading on it but would appreciate a brief explanation if it's not a hassle.

question from:https://stackoverflow.com/questions/66049988/two-implementations-of-geometry-reader-but-one-isnt-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. You get the error Cannot find 'Content' in scope because that would not be the correct way to draw that information out. Note that within Apple's Docs, var content: (GeometryProxy) -> Content -- content is of type GeometryProxy and in your case you have content returns a closure containing GeometryProxy. These are 2 different statements.

  2. GeometryProxy contains all the information related to GeometryProxy, here is Apple's document on that.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...