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

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.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.