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

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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.