Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a UIGobblerGestureRecognizer?

I have just a regular UITableView, and I ran this code:

UITableView *tableView = [[UITableView alloc] init];
for(UIGestureRecognizer *gesture in tableView.gestureRecognizers)
 {
   NSString *className = NSStringFromClass([gesture class]);
   NSLog(@"ClassName:%@", className);
 }

One of the output lines is: ClassName:UIGobblerGestureRecognizer

Surprisingly Google has nothing on this. Anyone have any idea what it is?

like image 543
Snowman Avatar asked Apr 27 '12 17:04

Snowman


5 Answers

Most likely this is an internal class that Apple uses. I've come across custom subclasses of UIGestureRecognizers that Apple created for some specific use. I'm sure they have needed to create custom gesture recognizers for various reasons, just as I have and not all of those classes are exposed for us to use.

like image 160
Aaron Hayman Avatar answered Sep 18 '22 16:09

Aaron Hayman


Check out http://oleb.net/blog/2013/02/new-undocumented-apis-ios-6-1/

BJ Homer believes UIGobblerGestureRecognizer is used to avoid recognition while animations are in progress. Otherwise, it’s inactive. In an interesting Twitter conversation, Filippo Bigarella and Conrad Kramer discovered that UIGobblerGestureRecognizer can “gobble” touches in order to prevent other gesture recognizers from receiving them in certain situations. What situations those are, I don’t know.

like image 28
smileyborg Avatar answered Sep 20 '22 16:09

smileyborg


I'm very sure it is used to prevent normal interaction while a particular cell is showing a delete confirmation button, and recognise any touch down as triggering that cell to return to a non-editing state.

It has this method and I'm assuming that excludedView is the cell that is showing a delete confirmation button, since you can normally still interact with cells in this state.

- (id)initWithTarget:(id)arg1 action:(SEL)arg2 excludedView:(id)arg3;

https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UIGobblerGestureRecognizer.h

like image 31
jamesmoschou Avatar answered Sep 21 '22 16:09

jamesmoschou


In short, from what I've read and what my experiments have shown, the "gobbler" seems to gobble up the swipes and touches on a table view (actually table cells) when a state transition (initiated by the user's touch or swipe) is in progress, so that the state transition can be completed before the user can touch the table again. Apple may use it in other cases but it is on the table view that I have observed the gobblers.

Now the long story: Suppose your table view implements a "drawer" on the table cell, like Apple's mail app or message app. When you open the drawer with a back swipe and take an action on any of the buttons in the drawer, all is well. But if you just close the draw with a forth swipe, you'll likely find that your next back swipe on a random cell doesn't work. But if you keep doing the back swipes, the next swipe usually will work again to show the drawer. Simply put, if you just open and close the drawer on random cells by using swipes, you'll find sometimes the drawer doesn't open.

I see this behavior on my table and thought I did something wrong. I tried many things and eventually implemented my own subclass of UITableView which also supports UIGestureRecognizerDelegate. In my subclass I implemented the delegate's shouldBeRequiredToFailByGestureRecognizer function, just to print out the gestureRecognizer and otherGestureRecognizer pairs. Then I found that when the back swipe is recognized, the gobbler is NOT present in the pairs. But when the back swipe is not working, the gobbler definitely IS present.

The general opinion on the web is that the gobbler is used to prevent the user from causing another state transition on the table while one transition is already in progress. That is fine if the user indeed takes some action (by touching a button in the drawer). But when the user just closes the drawer, the gobbler should be cancelled. Or the gobbler should be added ONLY when the user takes an action. After my realization, I went on to try my theory on Apple's apps. I already knew the Mail app behaves perfectly responding to every swipe. But the Message app behaves intermittently to repeated drawer opening swipes, much like my app. So I guess the developers of Mail are more careful and used internal knowledge to get it right. My observation is done on iOS 8.4 on iPhone 6 and iPad 2. And I believe the same gobbler issue dates back at least from the first iOS 8 release because I know my app had the issue from day 1 (months ago) but I just got around to look into the problem.

like image 21
Xiaolin Zang Avatar answered Sep 20 '22 16:09

Xiaolin Zang


it should definitely be part of private API ..

i will suggest to stay out of it

like image 34
Shubhank Avatar answered Sep 18 '22 16:09

Shubhank