Both view and subview receive mouse events?

  • Hi,

    I have a custom view viewA contained within a scrollview.  I wanted
    to add a subview viewB in viewA so I do something this (self is viewA):

        viewB = [[MyOverlayView alloc] initWithFrame:[self bounds]
    view:self];
        [self addSubview:viewB];

    After I do the above, viewB is created and inserted into viewB
    (completely overlaying it) but both viewA and viewB receive mouse
    events?  I overrode hitTest and all mouse events to make sure and it
    is indeed the case.  All events come to viewB first, then to viewA
    which seems to contradict what I expect based on the docs.

    However, if I change the code above to insert viewB not in viewA but
    in the scroll view containing viewA like the following:

        [[self superview] addSubview:viewB];

    then everything seems to be working more logically, only the top view
    viewB receives mouse events.

    I assume this is correct behavior but I cannot figure out why?

    So why do both viewA and viewB receive mouse events in the first case
    above?

    Cheers,

    -- ivan
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today