objective-cuigesturerecognizer

iOS Simulator Not Recognizing Gestures


I am adding a UISwipeGestureRecognizer and a UITapGestureRecognizer to a view in a view controller's viewDidLoad method.

- (void)viewDidLoad {
        [super viewDidLoad];
        [self.view addGestureRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cardSwipe:)]];
        [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cardTap:)]];
    }
- (void)cardSwipe:(UISwipeGestureRecognizer *)sender {
    //get the card. set faceUp to false.
    CGPoint location =  [sender locationInView:sender.view];
    NSIndexPath *cellIndex = [self.cardCollectionView indexPathForItemAtPoint:location];
    if(cellIndex){
        UICollectionViewCell *cell = [self collectionView:self.cardCollectionView cellForItemAtIndexPath:cellIndex];
        if(cell && [cell isKindOfClass:[CardCollectionViewCell class]]){
            [[((CardCollectionViewCell *)cell) cardView] handleCardSwipe];
        }
    }
}
- (void)cardTap:(UITapGestureRecognizer *)sender {
    //get the card. set faceUp to false.
    CGPoint location =  [sender locationInView:sender.view];
    NSIndexPath *cellIndex = [self.cardCollectionView indexPathForItemAtPoint:location];
    if(cellIndex){
        UICollectionViewCell *cell = [self collectionView:self.cardCollectionView cellForItemAtIndexPath:cellIndex];
        if(cell && [cell isKindOfClass:[CardCollectionViewCell class]]){
            [[((CardCollectionViewCell *)cell) cardView] handleCardSwipe];
        }
    }
}

In case this is relevant: The view contains a UICollectionView.

The taps and swipes are not getting recognized. Is there something obvious that I am missing? Thanks.


Solution

  • Turns out the view was not responding to any gestures - scrolling, taps on buttons or the swipe actions. I deleted generated folders from ~/Library/Application Support/iPhone Simulator / 6.1/Applications and ~/Library/Developer/Xcode/DerivedData, reset the simulator settings (from iOS Simulator > Reset Contents and Settings), did a clean in xcode (Product > Clean) and ran the app again. The gestures are now recognized. I am not sure which of the above fixed the problem...it is possible that simply resetting the simulator's contents and settings would have been enough.