strange quark
strange quark

Reputation: 5205

Getting a UIView beneath another UIView

I have a couple of UIViews in the same superview. One view which is on top I want to be able to be dragged around the screen while multiple UIViews beneath it react when it passes over them (the views on the bottom don't overlap). Right now, I have the draggable-view sending touch events to my UIViewController using a delegate protocol which is where I'd like to do all the logic.

Essentially, I'd like to be able to find out what view my draggable view is currently over in the view controller. Is there any easy way to do this?

Upvotes: 0

Views: 127

Answers (2)

Bot
Bot

Reputation: 11865

You will want to get the frames of the views and see if they intersect. There is a similar question with example code here Detecting if UIView is intersecting other UIViews

Upvotes: 0

David Hoerl
David Hoerl

Reputation: 41652

You can get the frames of all your views by walking the subview array of self.view (or your primary view). You can then do a test to see if a particular point is in one of the views, or if there is an intersection of the dragged view's current frame with any of the other frame.

There is a convenience method that lets you do this: CGRectIntersectsRect(r1, r2).

Upvotes: 1

Related Questions