hitTest:withEvent: UIEvent allTouches is empty
Asked Answered
E

1

16

I have a custom UIView that implements hitTest:withEvent:

-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    .... some code ....

    int x = 0;
    x = [[event allTouches] count];
    return [super hitTest:point withEvent:event];
}

The problem is that x is always 0. Do I have implement other APIs or configure the UIView to start getting the touches?

I only needed it in order to differentiate between touch start/move and end.

Erfurt answered 20/6, 2012 at 12:33 Comment(6)
What is shown by NSLog(@"Event: %@", event);?Leiker
Event: <UITouchesEvent: 0x6a1abc0> timestamp: 0 touches: {( )} Event: <UITouchesEvent: 0x6a1abc0> timestamp: 0 touches: {( )} Event: <UITouchesEvent: 0x6a1abc0> timestamp: 248999 touches: {( )}Erfurt
@PhillipMills hitTest gets called three times with the logs aboveErfurt
It worth mentioning that this custom UIView is used as a top level container\view in UIViewController. To use it, I only modified the xib file of the viewcontrollerErfurt
Touches aren't added to the event until after hit testing succeeds. What is it that you're trying to accomplish?Docile
"Touches aren't added to the event until after hit testing succeeds." Then why is the view getting the touch-type event in the first place? If you check event.type, it is UIEvent.EventType.touchesBurmaburman
P
-4

Try this

yourView.userInteractionEnabled = YES;

iOs provides the possibility to nullify the user interactions in the view hierarchies. Being said that in the chain of events on iOS it's possible to ignore the touch event in the most immediate view in the view stacks and then the next view in the hierarchy will try to take responsibility to respond to the interaction.

Being said all the previous it can be happening that the view that should respond to the user interaction is being set to NO, so the next view in the hierarchy will respond to the event. This can be the reason why it was not working for you.

Pacifa answered 4/10, 2013 at 20:49 Comment(1)
Why? Why should he try this? Edit your answer to be more informative.Abloom

© 2022 - 2024 — McMap. All rights reserved.