PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 29, 2022

[FIXED] how to make UISwipeGestureRecognizer work in a view with other gesture recognizers tvOS

 September 29, 2022     objective-c, tvos     No comments   

Issue

My UITapGestureRecognizer gestures work as they supposed to but I've been trying to Add UISwipeGestureRecognizer to my tvOS app but when I test it with the simulator it does not work!

here is my code :

- (void)addScreenControlGesturesRecognizers {
    UITapGestureRecognizer *_oneTapMediaControl = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapMediaControl:)];
    _oneTapMediaControl.numberOfTapsRequired = 1;
    _oneTapMediaControl.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeSelect]];

    [self.view addGestureRecognizer:_oneTapMediaControl];

    UITapGestureRecognizer *_doubleTapMediaControl = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleTapControl:)];
    _doubleTapMediaControl.numberOfTapsRequired = 2;
    _doubleTapMediaControl.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeSelect]];

    [self.view addGestureRecognizer:_doubleTapMediaControl];

    [_oneTapMediaControl requireGestureRecognizerToFail:_doubleTapMediaControl];

    UISwipeGestureRecognizer *_swipeGesturesControl = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeGestureRecognizer:)];
    _swipeGesturesControl.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:_swipeGesturesControl];

}

- (void)handleSwipeGestureRecognizer:(UISwipeGestureRecognizer *)recognizer {
        NSLog(@"Swipe Left"); 
}

Solution

You have to set your gesture recognizer to work simultaneously with other gesture recognizer. Please use UIGestureRecognizerDelegate's method

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    return YES;
}


Answered By - SergStav
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing