Objective C - UIPanGestureRecognizer selector not invoked with UISlider
Asked Answered
T

0

0

I am trying to using UIPanGestureRecognizer and UITapGestureRecognizer on UISlider. tap is working fine i am facing problem with UIPanGestureRecognizer. I need to call handleTransactionPan method on changing value of UISlider but it is never being called because of its delegate method.

How can i invoke the selector while keeping the delegate methods to fire? Here is the code for what i have done so far.

    - (void)viewDidLoad
{
    [super viewDidLoad];

    pr=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleTransactionPan:)];
    pr.delegate=self;
    [slider addGestureRecognizer:pr];

    tr=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    tr.delegate=self;
    [slider addGestureRecognizer:tr];

}

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

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

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if(gestureRecognizer==pr)
    {
        if ([touch.view isKindOfClass:[UISlider class]]) {
            return NO;
        }
    }
    return YES;
}
Trimerous answered 26/6, 2014 at 11:45 Comment(2)
I tried using pr.state inside UISlider value change method but the state of pr is not UIGestureRecognizerStateEnded instead it is UIGestureRecognizerStatePossibleTrimerous
not able to solve this yet so i dicided to create custom UIControl i uploaded it on githuh threestatesbutton LinkTrimerous

© 2022 - 2024 — McMap. All rights reserved.