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.
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.
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 ...
}
}
}
Look out for UISwipeGestureRecognizer as well. This was causing the issue for me and is resolved once we set
[recognizer setCancelsTouchesInView:FALSE];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With