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

Animating size with GeometryReader

Forums > SwiftUI

Hi there!

I have some very basic code in SwiftUI:

RoundedRectangle(cornerRadius: 15, style: .continuous)
                    .frame(width: geometryProxy.size.width * (hasAnimatedMask ? 0.75 : 1), height: geometryProxy.size.height * (hasAnimatedMask ? 0.65 : 1))
                    .position(x: geometryProxy.size.width * 0.5, y: geometryProxy.size.height * 0.5)

This is just animating a value based off of the hasAnimatedMask boolean. My goal was to make it have the exact width and height of the device and then just scale that down.

Sounds easy and it should be.

However, I am realizing that there is a small detail that makes this not work. When I change orientations of the device, the view does not update its size.

I just want to have a view be the size of the device and scale down, regardless of orientation.

What am I doing wrong?


Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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

Reply to this topic…

You need to create an account or log in to reply.

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.