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

SOLVED: How do I solve the challenges in on Day 94?

Forums > 100 Days of SwiftUI

I'm having trouble understanding these problems at a conceptual level.

The first challenge asks you to change the shrink an image as you scroll down the page using GeometryReader. But I honestly don't understand how I'm supposed to approach this problem at all.

How do I solve these challenges using GeometryReader values? All I understand is that I should probably use scaleEffect() somehow.

2      

Think about when you walk into your apartment. Siri chirps in and says, this room is 16 feet by 30 feet. Then you walk into the bathroom and Siri says, this room is 6 feet wide and 10 feet long. As you move from room to room Siri tells you the dimensions of the room you are in.

GeometryReader works on the same principle. It can tell you a number of values for its containing view. Awesome!

You have Geometry reader in the MissionView, yes? You also have a mission badge photo in the MissionView. But it stays the same size when you scroll to the bottom to see the astronauts, yes?

What if you could determine how far down the MissionView you are? Say you were 50% down the view, maybe you could update a State variable and apply a percentage to the size of the Mission Badge? When you reach 80% down the view, the State variable is automatically updated, and so is the MissionBadge's size. When you get to the bottom of the view the MissionBadge is reduced to half its normal size. There is some math involved here.

But what you need to find out is HOW do you determine HOW FAR down the view you are.

@twostraws has a nice video Scroll View Using Geometry Reader

This video has some hints for you! Review this a few times. Think how you might apply these techniques. Try a few things, then come back and tell us about your success!

3      

I figured it out. The part that helped the most was figuring out that the nested GeometryReader was inside a ScrollView, and was moving. So every time the ScrollView updates, GeometryReader gave me a new position.

All that was left was to use frame(in:) to get those values from GeometryReader, and apply a little bit of math to solve the challenges.

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.