UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

ScrollViewReader anchor center creates free space

Forums > SwiftUI

Hello there I want to zoom in on a specific element in the scrollview. I want it to be an anchor center. When zooming to the upper left elements, no problem, it works properly. But when you zoom in on the top right and bottom elements, space is created around it. I showed in the pictures. how can i solve this? thank you.

            GeometryReader { geo in
                ScrollView(detect.scrolID != nil ? [.horizontal,.vertical] : []) {
                    ScrollViewReader { reader in
                        BoardView(changeFrame: self.changeFrame, spotFrames: $spotFrames)
                            .frame(width: detect.scrolID != nil ? geo.size.width  * 2 : geo.size.width , height:  detect.scrolID != nil ? geo.size.width * 2 : geo.size.width)
                            .onChange(of: detect.scrolID){ value in
                                if value != nil {
                                    if camerazoom{
                                        reader.scrollTo(value, anchor: .center)
                                    }
                                }
                            }
                    }
                }
                .background(Color.blue)
            }

first loaded version of the page first load

Works correctly when zooming in on top left elements enter image description here

When zooming to the following elements, these gaps appear enter image description here

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.