Skip to content

GeometryReaders

Nick Sarno edited this page Apr 11, 2022 · 3 revisions

FrameReader

Adds a transparent View and read its frame.

FrameReader(coordinateSpace: .global) { frame in
     let minX = frame.minX
     let minY = frame.minY
     let maxX = frame.maxX
     let maxY = frame.maxY
     let width = frame.width
     let height = frame.height
}

.readingFrame

Get the frame of a View.

Text("Hello, world!")
     .readingFrame { frame in

     }

LocationReader

Use LocationReader if you only need a CGPoint. This limits the new View's frame to .frame(width: 0, height: 0).

LocationReader { location in
      let xPosition = location.x
      let yPostition = location.y
}

.readingLocation

Get the center point of a View.

Text("Hello, world!")
     .readingLocation { location in

     }
Clone this wiki locally