Swift: How to tell which UIView(s) myView is intersecting with?

885 Views Asked by At

I have an array of 16 boxViews, which are present in random locations on my superview. I am dragging myView which is a special subView. I need to be able to tell which boxView(s), myView is intersecting with, at any given time. How do I do achieve that?

1

There are 1 best solutions below

2
On

Suppose you have boxViews that is an array of all the view in your super view. And all UIViews in boxViews have the same immediate super view. And that myView is among the views in boxViews.

let intersectedViews = boxViews.filter { $0 !== myView }
                               .filter { CGRectIntersection(myView.frame, $0.frame) }