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
4
votes
1 answer

SwiftUI ScrollView: find subview that is currently visible at center of screen. Subview's position within ScrollView. PreferenceKey. ScrollViewProxy

The Challenge: I would like to track which subview of a ScrollView is in the middle of the visible area of this ScrollView. The Problem: I understand that there is no native SwiftUI way of finding out whether a ScrollView's subview is currently…
KlausM
  • 193
  • 12
4
votes
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,505
  • 3
  • 25
  • 49
4
votes
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…
4
votes
2 answers

SwiftUI: Build View from bottom alignment in scrollView

Is there a way to build UI elements in SwiftUI inside scroll view with bottom Alignment? My use case: I have a screen where the screen has Spacer (What ever is left after allocating below elements) LogoView Spacer() - 30 Some Text - 4/5…
Pablo Dev
  • 317
  • 5
  • 16
4
votes
2 answers

GeometryReader to calculate total height of views

I have a main view with a fixed width and height because this view will be converted into a PDF. Next, I have an array of subviews that will be vertically stacked in the main view. There may be more subviews available than can fit in the main view…
squarehippo10
  • 1,855
  • 1
  • 15
  • 45
4
votes
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,584
  • 25
  • 44
4
votes
2 answers

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
  • 4,082
  • 3
  • 17
  • 33
4
votes
1 answer

Is there a way to define the width of my SwiftUI Image to be relative to screen size using Geometry Reader?

I am working through a sample app to familiarize myself with Swift and SwiftUI and am wanting to combine the ideas of composite layouts using custom views and GeometryReader to determine the screen-size of the device. The page I'm trying to build…
Mdank
  • 103
  • 6
4
votes
1 answer

SwiftUI different children alignment and GeometryReader

I want to transform a web app into an iOS app and I am struggling with alignments and the GeometryReader(). This a a screenshot from my original web app template: This is my current version in SwiftUI: With the related code: struct PileRow: View…
T. Karter
  • 638
  • 7
  • 25
4
votes
2 answers

SwiftUI GeometryReader compact size

I would like my LoadingTitle to have a width of 70% of the screen so I use the GeometryReader but it makes the vertical size expand and my LoadingTitle takes much more vertical space. I would like it to remain as compact as possible. When using…
Jan
  • 7,444
  • 9
  • 50
  • 74
4
votes
1 answer

How do I get my UIView to correctly size for its content in SwiftUI?

I want to use the awesome MultiSegmentPicker written by Yonat Sharon in my SwiftUI View. https://github.com/yonat/MultiSelectSegmentedControl However, I don't fully understand the interaction between the UIViewRepresentable View and my SwiftUI View.…
Mozahler
  • 4,958
  • 6
  • 36
  • 56
4
votes
1 answer

why is VStack not working in GeometryReader with scrollview?

My scrollview with vStack worked (in AppleTV - i did not test in iOS) without GeometryReader. Then i added the geometryreader and the VStack "collapses" like a ZStack. What can i do to solve this? (and yes, i need the geometryreader ;)) struct…
Chris
  • 7,579
  • 3
  • 18
  • 38
4
votes
2 answers

SwiftUI: Drawing rectangles around elements recognized with Firebase ML Kit

I am currently trying to achieve to draw boxes of the text that was recognized with Firebase ML Kit on top of the image. Currently, I did not have success yet and I can't see any box at all as they are all shown offscreen. I was looking at this…
4
votes
1 answer

How to use GeometryReader without it filling the View

This is the layout I'm aiming for. import SwiftUI import PlaygroundSupport struct TestView: View { let text: String var body: some View { Text(self.text) } } struct ContentView: View { var body: some View { …
Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
3
votes
4 answers

SwiftUI Cut out hole for view in dark overlay for tutorial-like highlighting

I'm trying to create a tutorial framework in SwiftUI that finds a specific view and highlights it by darkening the rest of the screen. For example: Say I have three circles... And I want to highlight the blue one... Here's what I have come up with…
Jared
  • 793
  • 6
  • 16
1
2
3
12 13