7

Slide to the left & amp; The right works all the time, but sliding up / down...

 3 years ago
source link: https://www.codesd.com/item/slide-to-the-left-the-right-works-all-the-time-but-sliding-up-down-does-not-work.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Slide to the left & amp; The right works all the time, but sliding up / down does not work

advertisements

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?

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;
}


Try setting the delegate of your Upward swipe and downward swipe to be your MainViewController.Something like :

swipeDown .delegate  =   self;
swipeUp .delegate = self;

This should make your main view controller ( which contains the secondary UIView ) responsible for the gestures received.

Hope this helps!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK