Questions tagged [geometryreader]

A container view that defines its content as a function of its own size and coordinate space. Returns a flexible preferred size to its parent layout.

It's a component of Apple's SwiftUI language.

Learn more from Apple's documentation

184 questions
1
vote
1 answer

SwiftUI view changes layout when multiple views included

I'm trying to design a mixing desk for an iPad app using SwiftUI. I have an image for the background of the fader and will be using a slider stacked on top of it to change the volume. I have a View called faderView() which contains the image and the…
Wpitchy
  • 97
  • 6
1
vote
1 answer

How to get size of a given element (eg. button)

I am trying to get the size of a button. The button's frame size is dynamic based on the text size. How can I do this? I tried wrapping this in a GeometryReader, and reading the geo.size.height, etc, but this returned 10 every time, and messed up…
Joseph
  • 691
  • 4
  • 18
1
vote
0 answers

How can I track scrolling with a ScrollView linked to a Custom PageControl - SwiftUI

I want to create a Carousel with SwiftUI(without using TabView) with a matching/linked Page Control in SwiftUI So far I have both views and can update the pageControl view with a @State var pagecontrolTracker updated with a DragGesture() .onChanged…
Di Nerd Apps
  • 770
  • 8
  • 15
1
vote
1 answer

GeometryReader coordinateSpace returning incorrect frame

I am having trouble getting geometry reader working with a coordinateSpace, I have simplified my problem into a demo: struct AddTransaction: View { // MARK: - Views var body: some View { NavigationView { GeometryReader…
Kex
  • 8,023
  • 9
  • 56
  • 129
1
vote
0 answers

How to access the proposed width of a view within a ScrollView in SwiftUI on iOS 14?

I'm trying to achieve the following layout with SwiftUI in iOS 14: I have an inner ScrollView with a couple of "cells" each of which has the same aspect ratio. This inner ScrollView scrolls its content horizontally and is part of a view tree that…
Mischa
  • 15,816
  • 8
  • 59
  • 117
1
vote
1 answer

Refactor GeometryReader code extracted to subview in SwiftUI

My App is working, but there is a lot of repetative code. I can't figure out how to refactor the GeometryReader also how could I change the code using a ForEach to comply with MVVM Design Pattern. Last should this be put into a vertical…
1
vote
1 answer

SwiftUI GeometryReader causing havoc

I have the following view: var body: some View { ScrollView { VStack { HStack { Text("Something") Text("Something") } GeometryReader { geo in VStack { …
Azurlake
  • 612
  • 1
  • 6
  • 29
1
vote
4 answers

Using a Geometry Reader within a ScrollView is causing items to overlap

I want to be able to show an array of notes in a ScrollView. Each of these objects contains a GeometryReader, and I'm having trouble setting each of these object's height by the amount of content that is in it. I've made a reproducible example below…
Hal219
  • 61
  • 5
1
vote
1 answer

SwiftUI, multiple GeometryReader do not read the individual component's location correctly

When I created three Button()s View and I want GeometryReader to access individual Button()'s location in the frame. Although in the UI the Button()s show their location according to .position() modifier, the GeometryReader, however, print out the…
Jason
  • 3,166
  • 3
  • 20
  • 37
1
vote
1 answer

How do I center an Image view in pdf format with SwiftUI?

I have a vector (converted to Pdf) that I want to use as my background for my app. However, the Image is aligned all the way to the left as you'd expect when using GeometryReader. Perhaps it's not even GeometryReader doing this! Here is a photo: As…
Tomas
  • 135
  • 1
  • 6
1
vote
1 answer

SwiftUI calculate coordinate of the corner of UIimage

I'm looking to find the correct coordinate x,y of the 4 corners of the image display in the view. I wrote this code.. to calculate the first top left corner coordinate : but is wrong .. result should be 0 on x and y some value. my code: struct…
Damiano Miazzi
  • 1,514
  • 1
  • 16
  • 38
1
vote
2 answers

How to size subviews in HStack by percentage without GeometryReader (SwiftUI)?

I've got a simple HStack with subviews inside. How can I tell the first subview to be 60% the size of the HStack without using a GeometryReader? struct ContentView: View { var body: some View { HStack { …
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48
1
vote
0 answers

SwiftUI Geomteryreader in ForEach does not set height of child dynamically

First off, I'm trying to learn SwiftUI so I may not have a full understanding of how it works. I have an array of sentences that I use in a ForEach loop, that creates a GeometryReader with a Text view for each sentence. The length of each sentence…
Holger
  • 69
  • 1
  • 4
1
vote
1 answer

How to use GeometryProxy outside of a ViewBuilder?

I implemented a BasicContainer upon GeometryReader with the functionality of a @ViewBuilder. How can I use this inside GeometryProxy, outside when declaring the content? Here is my BasicContainer: struct BasicContainer : View { …
LukeSideWalker
  • 7,399
  • 2
  • 37
  • 45
1
vote
1 answer

Make view in scroll view centered in available space between top vstack with labels (it can change)

I have scroll view in which on the top can be different number of texts, from zero to many. And in the center I have another view which should be vertically centered in AVAILABLE SPACE, so if we have no texts on the top - my view should be in the…