GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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+

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 more!

Learn more here

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.