Objective C - UIPanGestureRecognizer选择器未使用UISlider调用

时间:2014-06-26 11:45:46

标签: ios objective-c uislider uipangesturerecognizer

我正在尝试在UISlider上使用 UIPanGestureRecognizer UITapGestureRecognizer 。点击工作正常我遇到了 UIPanGestureRecognizer 的问题。我需要在更改UISlider的值时调用 handleTransactionPan 方法,但由于其委托方法,它永远不会被调用。

如何在保持委托方法触发的同时调用选择器?这是我到目前为止所做的代码。

    - (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;
}

0 个答案:

没有答案