iOS Developer

长按移动框架

2017-03-14  本文已影响102人  喵喵嘟噜啡

比如先创建个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];

}

上一篇 下一篇

猜你喜欢

热点阅读