比如先创建个button
button上加上这个长按手势
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:selfaction:@selector(PanAnyWhere:)];
[button addGestureRecognizer: panGestureRecognizer];
长按的实现
- (void)PanAnyWhere:(UIPanGestureRecognizer*)recognizer
{
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center=CGPointMake(recognizer.view.center.x+ translation.x,
recognizer.view.center.y+ translation.y);
[recognizer setTranslation:CGPointZeroinView:self.view];
}







网友评论