209 questions
79
votes
7
answers
27k
views
Putting a LazyVStack or LazyHStack in a ScrollView causes stuttering
Xcode Version 12.4 (12D4e)
I have encountered this every time I have implemented a Lazy stack within a ScrollView:
Add a LazyHStack to a horizontal ScrollView or a LazyVStack to a vertical ScrollView
...
14
votes
3
answers
6k
views
ScrollView not working when DragGesture is enabled in subview
Ever since Xcode 16, whenever there is a subview with a horizontal DragGesture inside a vertical ScrollView, horizontal drag gesture is detected on the subview but any scrolling up/down is not ...
13
votes
4
answers
4k
views
ScrollViewReader scrollTo with .center anchor bug?
So I'm try to use ScrollViewReader to programmatically scroll a horizontal scroll view. I thought it would work like scrollToItem with .centeredHorizontally in UIKit, and for the most part it does, ...
11
votes
2
answers
1k
views
Issue using matchedGeometryEffect animation in ScrollView
Animating Views between a LazyVGrid and an HStack with another view in between them (in this case, a Button), using matchedGeometryEffect, works great:
Note how the animating views move above the ...
10
votes
3
answers
7k
views
Scroll View Items Come Over the Navigation Bar in SwiftUI
I made a custom nav bar. and added a scroll view below it. The problem I am getting is when I scroll down, the data inside scroll view comes over the navigation bar. Here is the screenshot:
My code ...
10
votes
0
answers
2k
views
How to use TabView or ScrollView for carousel?
I'm trying to create a carousel like some of Apple's apps. The TabView has the paged style but it doesn't "peek" at the previous and next elements. The ScrollView(.horizontal) doesn't snap. ...
9
votes
4
answers
3k
views
SwiftUI ScrollView does not center content when content fits scrollview bounds
I'm trying to have the content inside a ScrollView be centered when that content is small enough to not require scrolling, but instead it aligns to the top. Is this a bug or I'm missing adding ...
9
votes
2
answers
3k
views
TabView with PageTabViewStyle() not using available height in ScrollView
so I have a TabView like shown below, but when I try to implement it in a ScrollView I always have to give it a fixed height. Is there a way of telling the tabview to use the space it needs in the ...
9
votes
2
answers
2k
views
SwiftUI viewAligned scrollTargetBehavior for ScrollView where scrollTargetLayout subviews are irregular in size
I'm trying to use SwiftUI's viewAligned scrollTargetBehavior for a ScrollView where scrollTargetLayout subviews are irregular in size.
Here's an example, which I've simplified for the purpose of ...
9
votes
1
answer
4k
views
SwiftUI - How to Tell When a User Interacts with the Scroll View and not Programmatically?
I am trying to find out when the user interacts with a horizontal ScrollView in SwiftUI. The problem is that most solutions that I have found are based around when the scroll view moves. This doesn't ...
8
votes
2
answers
2k
views
SwiftUI ScrollView maintain position on new page load
In my chat view, each time I load new page (items are added from top), the ScrollView jumps to top instead of maintaining scrollPosition.
Here is my scroll view:
GeometryReader { geometryProxy in
...
8
votes
0
answers
1k
views
SwiftUI ScrollView scrolls too far when using scrollViewReader
I'm creating an app where I'm presenting data in paged views and each view contains a vertical scrollable list, enabled by scrollView. I'm also using scrollViewReader to be able to programmatically ...
7
votes
5
answers
587
views
How can I scale the height of child items with a magnify gesture while preserving the scroll position in a SwiftUI ScrollView?
I am trying to create a day calendar view, similar to the iOS calendar app. There is a feature on the app where you can pinch the calendar to change the distance between hours, which I am trying to ...
6
votes
5
answers
1k
views
Disable Interactive Dismissal of Navigation Transitions in SwiftUI
I am using the new navigationTransitionStyle(.zoom(id, namespace)) to zoom from a view preview to a detail view in my swiftUI app.
My issue is that I have a snapping scrollView in the detail view, ...
5
votes
1
answer
2k
views
iOS SwiftUI ScrollView in NavigationStack: Scroll To Top Doesn't Finish Expanding Navigation Title, If Animated
I'm needing to implement a scroll-to-top button for a ScrollView living in a NavigationStack, but when I call proxy.scrollTo() (with proxy being the ScrollViewProxy provided by ScrollViewReader), the ...
5
votes
6
answers
6k
views
SwiftUI: ScrollView that drags bottom sheet with it
I'm trying to create a SwiftUI Scrollview that drags its container like this: https://drive.google.com/file/d/1O92DgsVI1OjM1HEUXUwVywB8gcdShOP-/view?usp=sharing
Many Apple apps use this (Apple Maps, ...
5
votes
1
answer
1k
views
How do I modify the background color and shape of drag&drop preview SwiftUI?
I'm trying to implement simple list with draggable cells (iOS 15). For now I have two base solutions: List and ScrollView. None of this methods doesn't lead me to appropriate result.
First of all I'll ...
5
votes
0
answers
282
views
SwiftUI 2.0 Keyboard Avoidance set ScrollBar offset
I'd like to change the ScrollBar offset when tapping on a TextField in a ScrollBar which is located at the bottom (so keyboard avoidance will trigger).
When I select a TextField, the ScrollBar adjusts....
4
votes
2
answers
6k
views
SwiftUI: Pin headers in scrollview which has vertical and horizontal scroll in excel like view
I created an excel-like view, using a multi-directional scroll view. Now I want to pin the headers, not only the column headers but the row headers as well. Look at the following gif:
Code I used to ...
4
votes
2
answers
3k
views
ScrollView takes the entire height when content is small
I'm new to Swift UI and I'm having troubles to make a specific UI behave the way I want.
I have a ScrollView that has some content. This content in a VStack can be as small as 1-3 text components to ...
4
votes
1
answer
8k
views
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 ...
4
votes
1
answer
5k
views
SwiftUI ScrollView gesture recogniser
How can I detect when a ScrollView is being dragged?
Within my ScrollView I have an @Binding scrollPositionOffset variable that I watch with .onChange(of:) and then programmatically scroll to that ...
4
votes
2
answers
3k
views
SwiftUI - Calculate height for long GeometryReader inside ScrollView
Based off of this question: SwiftUI - Drawing (curved) paths between views
I draw the needed views and paths using the GeometryReader. The problem is, now it becomes too long for the screen to show it ...
4
votes
1
answer
437
views
Is there a way to use scrollview RTL (arabic) with LTR animation?
When you turn the ScrollView left to right, and try to scroll, content jumps to the other side. Is there any way to prevent this?
Main:
var body: some Scene {
WindowGroup {
ContentView()
...
4
votes
1
answer
1k
views
SwiftUI: ScrollView with paging scrollTargetBehavior shows end of previous page in current page
I’m trying to show a list of pictures in my app using ScrollView and .scrollTargetBehavior(.paging) modifier. But when swipe to next page, the view does not start at the beginning of the next image, ...
4
votes
2
answers
2k
views
SwiftUI: horizontal ScrollView inside NavigationLink breaks navigation
I want to use a simple horizontal ScrollView as NavigationLink inside a List. However, tapping on the ScrollView is not registered by a NavigationLink and therefore does not navigate to the ...
4
votes
3
answers
768
views
ScrollView with .viewAligned and .scrollPosition() not updating on orientation / size changes
The scroll position is not updated when orientation changes in a ScrollView with .scrollTargetBehavior(.viewAligned) and .scrollPosition().
import SwiftUI
struct ContentView: View {
let colors: [...
4
votes
0
answers
3k
views
SwiftUI: performance problems with ScrollView + LazyVStack + ForEach
Problem Outline: What I set out to build
I'm trying to build some sort of reader app and I'm running into severe performance issues with several approaches. If you know how to do this, please read the ...
4
votes
0
answers
1k
views
SwiftUI How to automatically scroll ScrollView with expanding TextField?
I am working on a feature for my app which will allow user to dictate text which will appear in a textField. For that I created a scrollView with only a textField which contents are automatically ...
4
votes
1
answer
3k
views
Resetting ScrollView position to the top of the page
I'm trying to make the scroll reset to the top of the page when a view appears (e.g. when you navigate back from a navigation link). The ScrollView is embedded within a NavigationView with a large ...
3
votes
1
answer
4k
views
SwiftUI scrollview sticky header without using List
I've been fighting with GeometryReader and .onChange(of: geo.frame(in: .global).minY) for a long time trying to get this to work with no great success. Consider the following:
struct TestScreen: View {...
3
votes
1
answer
3k
views
SwiftUI: How to scroll a list inside a sheet without dragging the sheet to the top
I have prepared a simple example. If you tap on the button, a sheet will be presented containing the CustomSheetView. Do not behalf on the design itself it is more about the scrolling behaviour. If I ...
3
votes
2
answers
1k
views
Detect when the user has scrolled to the end of a horizontal ScrollView in SwiftUI
I have created a horizontal carousel using a ScrollView with an HStack.
This is my code:
struct CarouselView<Content: View>: View {
let content: Content
private let spacing: CGFloat
...
3
votes
1
answer
3k
views
SwiftUI How can I center content in a dynamic horizontal scroll view when the total content width is less than screen width
I have a horizontal scrollView which shows a bunch of images from a dynamic image array. When the total content width is greater than the screen width everything is fine. However if say there is ...
3
votes
5
answers
2k
views
ScrollViews at the bottom of NavigationStack cause the navigation title to be invisible in iOS 26
I have a NavigationStack that contains a ScrollView at the bottom of the screen.
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
...
3
votes
3
answers
629
views
Override spacing for a child element in a SwiftUI HStack
I have a horizontal scroll user experience with a ScrollView and an HStack. I wanted to figure out a way to realize that the user has reached the end of the HStack.
To accomplish that, I used this ...
3
votes
1
answer
865
views
How to achieve the fade plus sticky header screen effect in SwiftUI
I would like to achieve attached gif effect in swiftUI, i have tried to make use of several ways to get it to work with no success. When scrolling up the buttons must fade and then once the switcher ...
3
votes
0
answers
1k
views
Get first visible view (item) inside a ScrollView that stores a LazyVStack
I have a ScrollView that will support infinite scroll (it’s a calendar), and so I’m using a LazyVStack for its contents.
I need to know at all times what the first visible item is. To be clear, as ...
3
votes
0
answers
2k
views
SwiftUI: Infinite, lazy, scrollable view that shows arbitrary cell on appearance
thank you for helping me with the following issue.
The Overall Goal
I work on a SwiftUI view that contains a scrollable area to present some data. Assume it should display natural numbers within a ...
3
votes
0
answers
2k
views
How to make ScrollView refreshable swiftui?
With Swiftui 3 Apple added modifier refreshable. I can use it with List. But if I have scrollview it doesn't work. Any ideas?
ScrollView(.vertical) {
LazyVGrid(columns: columns, spacing: ...
3
votes
0
answers
2k
views
SwiftUI iOS 14/15 Can't tap Button underneath Spacer in ScrollView
In SwiftUI, I have a Button that's underneath the Spacer within a ScrollView. The ScrollView steals the tap gesture, so the Button never sees the tap.
So, for example, the button in this example does ...
3
votes
0
answers
342
views
SwiftUI Disabling Keyboard Avoidance for item below a ScrollView in a VStack
I'm having some issues surrounding disabling keyboard avoidance in SwiftUI. My app has a custom tab bar which sits in a VStack underneath the content of the root view. However, most of my views have ...
3
votes
1
answer
891
views
How do I fix buttons not being tappable in a ForEach loop?
I have a view which contains a button. The view with the button is created from a forEach loop. For some reason only some buttons are tappable and others are not.
The parent view contains a ...
3
votes
0
answers
932
views
SwiftUI Calendar on scroll get current month
Im trying to get the current month when the calendar is being scrolled. My goal is to have the header with the current month, then when the view is scrolled down to a new month the header updates ...
3
votes
1
answer
4k
views
Navigationbar title is inline on pushed view, but was set to large
I want a large title in the navigationbar on a pushed view in SwiftUI and an inline title on the parent view.
When the parent navigation bar display mode is not set, it works:
Working without display ...
2
votes
1
answer
969
views
NavigationLink inside LazyVGrid is not displayed correctly in swiftUI macOS
I am developing a cross platform app in SwifUI. On iPhone / iPad this code works really well on MacOS instead when I insert a NavigationLink the ForecastCardView is totally cut off. When I remove the ...
2
votes
1
answer
2k
views
Dynamically set horizontal scroll view height based on max content height in SwiftUI
I am trying to create a horizontal carousel using SwiftUI ScrollView
This is what I have done so far:
struct CarouselView<Content: View>: View {
let content: Content
@State private var ...
2
votes
4
answers
3k
views
Preserve Scroll Position in ScrollView when Adding New Items
I am currently struggling on my ChatView of my app. This is a sample code of what i want to achieve. It has functionality such as when the user is about to reach the top it fetches older messages and ...
2
votes
1
answer
1k
views
SwiftUI add border to onSelect horizontal Scrollview image
I tried to make a horizontal scrollview that contained a list of item. when I clicked any of the item, it will show a border(highlight) behind the item. When I press another item, the previous border ...
2
votes
1
answer
243
views
@AppStorage var inside ScrollViewReader does not update view
I have an issue with @AppStorage and ScrollViewReader that seems like a bug.
My @AppStorage variable fontSize is supposed to adjust the text size inside a ScrollViewReader. However, when its value ...