NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Is there a SwiftUI View 'ClipToBounds' equivalent?

Forums > SwiftUI

I have a ScrollView with many rows, each row has a Button/icon I want to 'throw away' into the bottom corner of the App when it is tapped on. Something nicer than an alert to show the effect of tapping on the button.

Of course the position of the button is not fixed due to the scrolling of the various rows.

I created a simple animation in the Row view which can animate the icon offset in the onappear modifier:

@State private var offset: CGPoint = CGPoint(x: 0, y:0)

on the view:

.offset(x: offset.x, y: offset.y) .onAppear { let baseAnimation = Animation.easeInOut(duration: 1) withAnimation(baseAnimation) { offset = CGPoint(x: 100, y: -100) } }

This makes the button fly off the row but will disappear once it's bounds is outside the parent row view.

Is there an 'easy' way to make it fly outside it's parent view? Like turning off it's cliptobounds function? I vaguely remember something about SwiftUI views only existing in parent views and such a feature is not possible...

Thanks in advance.


Subscribe to Hacking with Swift+

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

Not logged in

Log in

Link copied to your pasteboard.