Search code examples
objective-cuitableviewuislider

UISlider in UITableView - Movement issue


The app contains content view and swipe menu view. The swipe menu is UITableView and it's part of the content view. In the swipe menu is UISlider. I added target for touchUpInside and touchUpOutside actions. When I drag the slider thumb and change value slowly, I can set value as usual. When I do it quickly then the thumb slider stuck near the start position of slider thumb and never set the value. I don't know if it's important but for sure I have to write that I register UIPanGestureRecognizer in content view controller (view of content view). For sure I'm adding picture of structure.

enter image description here


Solution

  • I've already solved it. It was issue with UIPanGestureRecognizer. The code:

    - (IBAction)panGesture:(UIPanGestureRecognizer *)recognizer {
    if ([recognizer.view isKindOfClass:[UISlider class]] || self.movieViewController) {
        return;
    }
    
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        startLocation = [recognizer locationInView:self.view];
    
        if (startLocation.x < 25) {
            [self.menuContainerViewController reloadData];
            [self hideBubble];
        }
    }
    
    if (isMenuShown) {
        if (startLocation.x > self.view.frame.size.width - 25) {
            CGPoint stopLocation = [recognizer locationInView:self.view];
            CGFloat distance = -self.view.frame.size.width + stopLocation.x;
            [self movementAnimation:distance];
        }
    }
    else {
        if (startLocation.x < 25) {
            CGPoint stopLocation = [recognizer locationInView:self.view];
            CGFloat distance = -self.view.frame.size.width + stopLocation.x;
            [self movementAnimation:distance];
        }
    }
    
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        CGRect frame = self.menuContainerViewController.view.frame;
    
        if (frame.origin.x + frame.size.width > self.view.frame.size.width / 2) {
            [self slideInAnimation];
        }
        else {
            [self slideOutAnimation];
        }
    }
    }
    

    And I added into my UIViewController:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UISlider class]]) {
        return NO;
    }
    return YES;
    }
    

    Now it works like a boss!