Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid Touches cancelled event?

I have two views one beneath the another. I'm rotating the below view by touch sensing of top view. while trying to make a swipe, touches canceled event is called before touches ended event. While moving the finger touches began and touches moved events are called , and then touches ended event is called at the last(mostly). But sometimes while trying to move slowly,touches canceled event is called stopping the touch events to occur. So i couldn't rotate view in slow speed. What may be the problem? how to avoid touches canceled event?

Note: I'm drawing some graphs in views using core-plot lib.

like image 503
Ka-rocks Avatar asked Apr 28 '11 12:04

Ka-rocks


3 Answers

If you are using any UIGestureRecognizers they automatically cancel touches to other views when they recognize their gesture. You can turn this behavior off with the cancelsTouchesInView property of the recognizer.

like image 127
Dancreek Avatar answered Nov 02 '22 00:11

Dancreek


If your are not using UIGestureReconizer directlly, be aware of the property gestureRecognizers of the UITouch. I have the same problem and with this code I solve it:

if (event.type == UIEventTypeTouches)
{
    NSSet* tmpTouches = [event  touchesForView:m_PhotoView];
    if ([tmpTouches count] == 2)
    {
        UITouch *tmpTouch1 = [[tmpTouches allObjects] objectAtIndex:0];
        UITouch *tmpTouch2 = [[tmpTouches allObjects] objectAtIndex:1];
        if ((tmpTouch1 != nil)&&(tmpTouch2 != nil))
        {
            UIGestureRecognizer * tmpG;
            if ([tmpTouch1.gestureRecognizers count] > 0)
            {
                tmpG = [tmpTouch1.gestureRecognizers objectAtIndex:0];
                tmpG.cancelsTouchesInView = NO;
            }
            if ([tmpTouch2.gestureRecognizers count] > 0)
            {
                tmpG = [tmpTouch2.gestureRecognizers objectAtIndex:0];
                tmpG.cancelsTouchesInView = NO;
            }
            // Code ...
        }
    }
}
like image 5
pocjoc Avatar answered Nov 01 '22 23:11

pocjoc


Look out for UISwipeGestureRecognizer as well. This was causing the issue for me and is resolved once we set

[recognizer setCancelsTouchesInView:FALSE];
like image 3
Srivaths Avatar answered Nov 01 '22 22:11

Srivaths