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

110 questions
1
vote
1 answer

Dynamic TextEditor overlapping with other views

So I have made a successful dynamic TextEditor but when I try to combine views, it overlaps the other elements and no longer expands as you type. I am pretty sure this has to do with Geometry Reader but I am not sure how to do it without that.…
1
vote
1 answer

Save ScrollViews position and scroll back to it later (offset to position)

I have found a way to save a ScrollViews offset with a GeometryReader and a PreferenceKey. SwiftUI | Get current scroll position from ScrollView And the ScrollViewReader has a method scrollTo to scroll to a set position. scrollTo The problem is,…
L3n95
  • 1,240
  • 2
  • 18
  • 40
1
vote
1 answer

SwiftUI: How to calculate a view's size based on it's frame's size without using a Geometry Reader?

The below code works great, however the geometry reading is causing me issues upstream, so I would like to have the same logic to build the view's width based on available space but without using Geometry Reader. Is it possible? var body: some…
GarySabo
  • 4,076
  • 5
  • 27
  • 76
1
vote
0 answers

SwiftUI: PreferenceKey is not called when parent view is embedded in NavigationView

DynamicScalingView is a child view with two buttons designed to have equal width & height using preferencekey Issue: When DynamicScalingView is embedded in NavigationView it not longer adapts to intrinsic and increases its frame size. Current…
1
vote
1 answer

SwiftUI HStack elements with equal height

I want both the buttons to have equal height similar to Equal Height constraint in UIKit. Don't want to specify the frame, let SwiftUI handle it but the elements in HStack should be of the same height. Buttons should have equal width and height and…
Pablo Dev
  • 117
  • 1
  • 12
1
vote
1 answer

GeometryReader seems to change layout of view that is using its size data. How can I avoid this?

I would like my icon image to be 1/3 the width of total screen availability. My code is as follows: var body: some View { GeometryReader { geometry in Image(systemName: "square.dashed").resizable() …
1
vote
1 answer

How to drag across Views in a LazyVGrid with GeometryReader?

I want to drag across rectangles in a grid and change their color. This code is almost working, but this is not always the right rectangle that reacts: it behaves rather randomly. Any hints? import SwiftUI struct ContentView: View { let data =…
1
vote
1 answer

How to position views relative to other views in different coordinate systems in SwiftUI

I'm trying to implement a drag and drop functionality in my app using SwiftUI. I create two circles which are located in two different HStacks. They do not share the same coordinate space. The circle with the stroke is the target, the green filled…
Marco Boerner
  • 481
  • 1
  • 3
  • 13
1
vote
0 answers

Best approach getting subviews to layout vertically in SwiftUI?

I'm having a hard time getting subviews to lay out correctly, especially the heights. I hate to hard code the subview heights but that is the only thing I can get to work. If I remove these frame(heights) from the subviews, the subviews overlap in…
GarySabo
  • 4,076
  • 5
  • 27
  • 76
1
vote
1 answer

SwiftUI: Why is the height of proxy.safeAreaInsets.bottom equal to keyboardHeight?

So the safeAreaInset.bottom on the iPhone 11 Pro Max is 34.0, but when the keyboard is open, it changes the safeAreaInset.bottom to the height of the keyboard (346.0 points). Is there any way to access the safeAreaInset.bottom value (34.0) when the…
nickcoding
  • 31
  • 3
  • 13
1
vote
1 answer

SwiftUI ScrollView VStack GeometryReader height ignored

I want to use a ScrollView outside of a VStack, so that my content is scrollable if the VStack expands beyond screen size. Now I want to use GeometryReader within the VStack and it causes problems, which I can only solve by setting the…
Janosch Hübner
  • 1,314
  • 17
  • 34
1
vote
1 answer

Using geometry reader to Center the Rectangle

I'm trying to use GeometryReader to make a Card View (to use in a card game). This Card is going to have 3 Shapes on it. I'm trying to center these 3 Shapes using GeometryReader (starting with the first shape, Rectangle), but it doesn't work. What…
1
vote
0 answers

SwiftUI iOS14 GeometryReader Invalid frame dimension

My GeometryReader was working fine in iOS13 but now in iOS14 i get a thread issue. "Invalid frame dimension (negative or non-finite)." I printed the size that the reader should give back and it looked fine. The app is still basically working, but…
C. Maier
  • 29
  • 5
1
vote
2 answers

SwiftUI Nested GeometryReader - Breaking UI

So I am trying to understand why my subview (TopView) is having weird resizing issues. Here is the sample import SwiftUI struct ContentView: View { @State var isInterfaceHidden: Bool = false var body: some View { VStack(spacing: 0,…
Oleg G.
  • 397
  • 2
  • 12
1
vote
1 answer

SwiftUI automatically sizing bottom sheet

There are a lot of examples of bottom sheet out there for SwiftUI, however they all specify some type of maximum height the sheet can grow to using a GeometryReader. What I would like is to create a bottom sheet that becomes only as tall as the…
Richard Witherspoon
  • 1,864
  • 3
  • 7
  • 21