Given one example here, ( with ARC )
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
[subView1 addGestureRecognizer:tapGesture ];
[subView2 addGestureRecognizer:tapGesture];
Here is the problem:
subView1 will not response to the tapGesture , but subView2 will.
subView1 will work if we remove tapGesture from subview2.
What happens inside in terms of memory management ? Why not design to make above code work ?
Im quite sure that the standard gesture recognizers included in iOS can only be attached to one view at a time. I can’t find anything that states it explicitly but if you look at the
UIGestureRecognizerclass there is aviewproperty with this description:So my guess is that
addGestureRecgnizer:will unattach the reconizer if it’s already attached to a view.