Gesture Recognizers and TableView

前端 未结 3 381
日久生厌
日久生厌 2021-02-02 17:13

I have a UIView which covers all of a UITableView. The UIView is using gesture recognizers for control of what the table displays. I still need the vertical UITableView scrollin

3条回答
  •  太阳男子
    2021-02-02 17:53

    I tried Rob Bonner's suggestion and it works great. thank you.

    But, in my case, there's a problem with direction recognition. (recognizer.direction always refer 3) I'm using IOS5 SDK and Xcode 4.

    It seems caused by "[gesture setDirection:(left | right)]" I think. (because predefined (dir left | dir right) calculation result is 3)

    So, if someone has problem like me and want to recognize swipe left and right seprately, then assign two recognizer to table view with different directions.

    Like this:

    UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] 
                                                 initWithTarget:self
                                                 action:@selector(handleSwipeLeft:)];
    [swipeLeftGesture setDirection: UISwipeGestureRecognizerDirectionLeft];
    
    UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc] 
                                                  initWithTarget:self 
                                                  action:@selector(handleSwipeRight:)];
    
    [swipeRightGesture setDirection: UISwipeGestureRecognizerDirectionRight];
    
    [tableView addGestureRecognizer:swipeLeftGesture];
    [tableView addGestureRecognizer:swipeRightGesture];
    

    and gesture action below:

    - (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
        [self moveLeftColumnButtonPressed:nil];
    }
    
    - (void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
        [self moveRightColumnButtonPressed:nil];
    }
    

    I coded with ARC feature then if you are not using ARC, add release codes.

    PS: My english is not so good, so if there's any sentential error, correction will be very pleased :)

提交回复
热议问题