I would like to know if it is possible to call a function when a UIView comes into contact with a collision boundary, but not to have them actually collide.
Can a function be called when they come into contact and have the view go right through the boundary?
If so, how?
Yes,
UIKitframework provides a nice collision detection facility.To respond to UIKit dynamic item collisions (e.g., views) configure a custom class to adopt the
UICollisionBehaviorDelegateprotocol. Then, in a collision behavior (an instance of theUICollisionBehaviorclass), set the delegate to be an instance of your custom class.In the aforementioned
UICollisionBehavioradd your view to it and configure your desired boundary using one of theaddBoundarymethods. Your delegate will then be notified of a collision in thecollisionBehavior(_:beganContactFor:withBoundaryIdentifier:at:)protocol function.(The default
collisionModeiseverything, so you can safely ignore this property for now.)