Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting UIGestureStateEnded in default UIScrollView pan gesture recognizer

My code:

[self.scrollView.panGestureRecognizer addTarget:self action:@selector(handlePanForScrollView:)];

- (void)handlePanForScrollView:(UIPanGestureRecognizer *)gesture {
switch (gesture.state) {
    case UIGestureRecognizerStateBegan:
        startScrollPoint = [gesture locationInView:self.scrollView];
        break;
    case UIGestureRecognizerStateEnded: {
        NSLog(@"end");
    }
    default:
        ;
        break;
    }
}

Began state works fine. But my NSLog shows my end all time while scrolling (as it should be state changed). What is the right way to detect the end state of gesture recognizer?

like image 242
RomanHouse Avatar asked Nov 28 '25 02:11

RomanHouse


1 Answers

did you consider to use and implement the "normal" methods of a UIScrollViewDelegate protocol? they should be enough for your uses, if you don't need else not mentioned in your question:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"scrolling now");
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    NSLog(@"stop scrolling");
}

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    NSLog(@"going to scroll");
}
like image 165
meronix Avatar answered Nov 30 '25 16:11

meronix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!