Search code examples
iosobjective-cuiviewuiswipegesturerecognizer

Swipe left & right works all the time, but swipe up/down doesn't


I have an object based on UIView that I've set up to recognise swipe gestures. The view has another UIView based object in the middle of it.

When I swipe left or right, regardless of where I put my finger, the correct event fires.

When I swipe up or down the correct event only fires if my finger isn't starting in the subview in the middle?

Why?

Here's the init code for the object:

- (id)init
{
    self = [super init];
    if (self) {
        [self setFrame:CGRectMake(0,
                                  0,
                                  [self getScreenWidth],
                                  [self getScreenHeight])];
        backView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                            0,
                                                            [self getScreenWidth],
                                                            [self getScreenHeight])];
        backView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backView];
        [self bringSubviewToFront:backView];

        theCard = [[actCard alloc] init:CARD_POS_CENTER];
        [backView addSubview:theCard];
        [backView bringSubviewToFront:theCard];

        swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                              action:@selector(showGestureForSwipeRecognizer:)];
        swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                               action:@selector(showGestureForSwipeRecognizer:)];
        swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                            action:@selector(showGestureForSwipeRecognizer:)];
        swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                              action:@selector(showGestureForSwipeRecognizer:)];
        [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
        [self addGestureRecognizer:swipeLeft];
        [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
        [self addGestureRecognizer:swipeRight];
        [swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
        [self addGestureRecognizer:swipeUp];
        [swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
        [self addGestureRecognizer:swipeDown];
        NSLog(@"Enabled: %d",swipeLeft.isEnabled);
        NSLog(@"Enabled: %d",swipeRight.isEnabled);
        NSLog(@"Enabled: %d",swipeUp.isEnabled);
        NSLog(@"Enabled: %d",swipeDown.isEnabled);

    }
    return self;
}

Solution

  • Obvious! What a newb I am. The UITextView still had scrollEnabled. That means the UITextView took the up & down swipes, they don't get passed on to the view.