Yes, UIKit
framework provides a nice collision detection facility.
To respond to UIKit dynamic item collisions (e.g., views) configure a custom class to adopt the UICollisionBehaviorDelegate
protocol. Then, in a collision behavior (an instance of the UICollisionBehavior
class), set the delegate to be an instance of your custom class.
In the aforementioned UICollisionBehavior
add your view to it and configure your desired boundary using one of the addBoundary
methods. Your delegate will then be notified of a collision in the collisionBehavior(_:beganContactFor:withBoundaryIdentifier:at:)
protocol function.
(The default collisionMode
is everything
, so you can safely ignore this property for now.)