ios - Why is hitTest:withEvent: called three times for each touch? -
i have subclass of uiview
in i've overridden hittest:withevent:
follows:
- (uiview *)hittest:(cgpoint)point withevent:(uievent *)event { nslog(@"event = %@", event); return self; }
for each touch in view, seeing 3 calls hittest:withevent:
. these 3 calls made before touch up. output follows:
2011-07-01 09:20:58.553 appname[930:207] event = <uitouchesevent: 0x6a08360> timestamp: 4297.16 touches: {( )} 2011-07-01 09:20:58.553 appname[930:207] event = <uitouchesevent: 0x6a08360> timestamp: 4297.16 touches: {( )} 2011-07-01 09:20:58.554 appname[930:207] event = <uitouchesevent: 0x6a08360> timestamp: 4304.54 touches: {( )}
based on timestamps , addresses, appears if single uitouchesevent
object being used , timestamp isn't set until third call. can explain why hittest:withevent:
gets called 3 times this? i'm not looking workaround. want understand what's going on.
i had same problem , able solve code. though pointinside , hittest called 3 times, touchesbegan (or touchesended) of uiview touched gets called once.
- (void)touchesbegan:(nsset *)touches withevent:(uievent *)event { if (event.type == uieventtypetouches) nslog(@"%@", self); } - (uiview *)hittest:(cgpoint)point withevent:(uievent *)event { if ([self pointinside:point withevent:event]) return self; return [super hittest:point withevent:event]; } - (bool)pointinside:(cgpoint)point withevent:(uievent *)event { if (cgrectcontainspoint([self bounds], point)) { if (event.type == uieventtypetouches) { return yes; } } return no; }
Comments
Post a Comment