Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block passing Gestures to SuperView

A ScrollView is there with some SubViews....
ScrollView Contains its predefined gestures(Pan) and my custom gesture(Pan) as well and Recognize it simultaneously...
SubViews also contains custom Pan Gesture......
Everything is working fine except pan gesture on SubViews ...
When i am doing pan on SubView its SuperView also getting touches and handling that which i don't want...
When pan is being done on the subViews, the superView Should not recognize them...
How i Can Block passing my SubView gesture to its SuperView?

like image 716
bhawesh Avatar asked Jan 13 '23 22:01

bhawesh


1 Answers

To block superview from responding to gesture, when there is subview under the touch point can be done as follows:

Implement the following method of UIGestureDelegate

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch;

as

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return  (touch.view == superView);
}

and set this delegate to gestureRecognizer assigned to superView.

I hope that this should do the needed.

like image 197
ajonnet Avatar answered Jan 19 '23 10:01

ajonnet