TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

ScrollView and NavigationView

Forums > SwiftUI

Hello everybody!

I am writing this post because I have an issue with SwiftUI.

There is a NavigationView and a NavigationLink for a new view (here: "Me") that contains several elements as you can see in the screenshot below. Me view

In the "Me" view, elements are displayed thanks to a ScrollView. But if I scroll, there is an issue with the NavigationBar as you can see here. Me scrolled

And if I use VStack instead of ScrollView, I have this result and I can't scroll: VStak

Do you know how I can resolve this problem ?

Thank you.

3      

Without seeing your code, can't give any really helpful suggestions.

Making the long story short, it appears the ScrollView is in conflict with the space provided by a NavigationView for the navigationBarTitle. At some point are you ignoring safe areas?

This is where previews and the canvas are really helpful, you'll be able to clearly see the outlines of the area.

I'm not sure about iOS14, but in iOS13 there's no real way to eliminate the space. There are several hacks if you search stackoverflow, but those will turn off the navigationBar on all your views. And it looks like you have a couple buttons there...

A quick workaround is to use navigationBarTitle("") or navigationBarTitle("", displayMode: .inline). You'll see your "Me" is no longer displayed and the navigationBar is more prominent. You may also want to apply a GeometryReader, but that will also preserve some space for the title. Try all this in the previews and watch how SwiftUI moves things around.

3      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

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.