views:

541

answers:

2

I currently have 1 UIView where I do custom drawing. I want to overlay that view with another view which has a few controls (label, button, etc). This overlayed view will be transparent so you can see the drawing view.

2 Questions:

1) Should I make the drawing view a sibling or child of the overlay view? 2) If its a child, do touch events (outside of those that goto the button) get to the drawing view automatically? If its a sibling, how do you pass the touch events?

Thanks.

+1  A: 

I dont believe touch events will get passed to another view automatically. You need to delegate it, there are a lot of ways to do this. One can be use a ViewController to manage between the 2 views, alert the view controller of touch events from view A and forward them to view B. If you want to tightly couple the two views, and one view contains the other, then the views should talk to each other when touches occur to inform that they have occured (might not be the best programing practice)

Daniel
A: 

So after some more experimentation, I found that if I use the following hiearchy:

  • overlay view | --- button | --- drawing view

In that order - then the touch events select the right view (i.e. events passed to button if clicked and passed to drawing view if touched.

aloo