Double tap inside a UICollectionViewCell

  • The code below from Collection View Programming Guide for iOS: Incorporating Gesture Support does not work as expected.  Is there something Apple has left out?

    Does not work as expected means @selector(handleTapGesture:)is not called if a double tap occurs in a UICollectionViewCell.  @selector(handleTapGesture:) is called if the double tap occurs outside a UICollectionViewCell.

    The question is how to get a double tap inside a UICollectionViewCell.

    -koko

        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
        NSArray* recognizers = [self.collectionView gestureRecognizers];
        for (UIGestureRecognizer* aRecognizer in recognizers)
        {
            if ([aRecognizer isKindOfClass:[UITapGestureRecognizer class]])

                [aRecognizer requireGestureRecognizerToFail:tapGesture];
        }
        [tapGesture setNumberOfTapsRequired:2];
        [self.collectionView addGestureRecognizer:tapGesture];
  • On Wed, 01 May 2013 18:23:10 -0600, koko <koko...> said:
    > The code below from Collection View Programming Guide for iOS: Incorporating Gesture Support does not work as expected.  Is there something Apple has left out?
    >
    > Does not work as expected means @selector(handleTapGesture:)is not called if a double tap occurs in a UICollectionViewCell.  @selector(handleTapGesture:) is called if the double tap occurs outside a UICollectionViewCell.
    >
    > The question is how to get a double tap inside a UICollectionViewCell.
    >
    > [self.collectionView addGestureRecognizer:tapGesture];
    >

    Well obviously if you want to detect double taps on a collection view *cell*, it might be simplest to attach the gesture recognizer to the collection view *cell* (not the collection view itself). m.

    --
    matt neuburg, phd = <matt...>, <http://www.apeth.net/matt/>
    A fool + a tool + an autorelease pool = cool!
    Programming iOS 6! http://shop.oreilly.com/product/0636920029717.do
  • On May 2, 2013, at 10:35 AM, Matt Neuburg <matt...> wrote:

    > Well obviously if you want to detect double taps on a collection view *cell*, it might be simplest to attach the gesture recognizer to the collection view *cell* (not the collection view itself). m.

    From the UICollectionView Programming Guide page 34:

    You should always attach your gesture recognizers to the collection view itself and not to a specific cell or view. The UICollectionView class is a descendant of UIScrollView. Attaching your gesture recognizers to the collection view is less likely to interfere with the other gestures that must be tracked. In addition, because the collection view has access to your data source and your layout object, you still have access to all the information you need to manipulate cells and views appropriately.

    I aint toopid and I kin reed  …

    -koko
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today