检测用户何时停止触摸UIButton

时间:2014-10-17 04:26:17

标签: ios objective-c uibutton

我有一个附有UIPanGesture的UIButton。当用户按下UIButton时,我调用事件Touch Down。我还想弄清楚用户是否可能将手指从按钮上抬起,之后可能会将其拖到屏幕上。我已经尝试过使用Touch Up InsideTouch Drag Exit这样的代表,但是在UIButton被拖了之后这些似乎不起作用......

1 个答案:

答案 0 :(得分:1)

仅在平移手势识别器开始时才会触发。如果用户只需点击按钮,它就不会触发。

-(void)setupGesture
{
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
    [self.yourButton addGestureRecognizer:pan];
 }


-(IBAction)handlePan:(UIPanGestureRecognizer *)sender
{
    switch (sender.state) {
        case UIGestureRecognizerStateEnded:
            //Should fire when the user lifts finger
            break;
        default:
            break;
    }
}