I have a UIImage
view that responds to touch events. I want to cancel the touch sequence, i.e., further calls to touchesMoved:
, if the touch goes o
Try temporary setting the UIImageView's userInteractionEnabled property to NO
I achieve this by removing the view from its superview and adding it straight back.
[view retain];
UIView *sv = view.superview;
[view removeFromSuperview];
[sv addSubview:view];
[view release];
This breaks the responder chain to the view so any remaining touches will not be received on the view. The next touch will still be received as normal.
You can check that, the touch point locations are in CGRect (ie. points are in Rectangle of your imageview) or not. If they are not in that Rect, the touch will be cancelled.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(myImageView, touchLocation))
{
lastPoint = [touch locationInView: myImageView];
}
NSLog(@"Last :%.2f - %.2f",lastPoint.x, lastPoint.y);
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint currentPoint;
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (CGRectContainsPoint(myImageView.frame, touchLocation))
{
currentPoint = [touch locationInView: myImageView];
}
}
You may create category to UITouch. You can to declare
@property (nonatomic,strong,readwrite) UIView *view;
And when you change touch.view to nil, for example, you can simulate end of dispatching touch events
"Brute force" solution depending if it suits your needs: Remove and re-initialize the subview that receives the touches or responds to them (of course take care of frame and content).
I was just trying to solve something like this, and found that none of the solutions listed her worked for me. The best i could manage was temporarily ignoring the touches, but then they resumed when the touch re-entered the view.
Finally solved it.
I guess this will work for you unless you have a specific reason for literally needing the touch sequence cancelled.