2014-10-17 105 views
1

我有一个附加了UIPanGesture的UIButton。当用户按下UIButton时,我将事件Touch Down称为事件。我也想知道用户何时将其手指从按钮上抬起,然后可能会将其拖到屏幕上。我尝试过使用代表,如Touch Up InsideTouch Drag Exit,但这些在UIButton被拖动后似乎不起作用...当用户停止触摸UIButton时检测到

+0

尝试UIControlEventTouchCancel – Suen 2014-10-17 04:35:23

+0

@ user3705414不幸的是,每当用户开始拖动时调用UIControlEventTouchCancel,我希望它在手指上的提升调用。 – Apollo 2014-10-17 14:52:58

回答

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