美文网首页
iOS 实现可拖动button

iOS 实现可拖动button

作者: 萨缪 | 来源:发表于2020-04-03 16:38 被阅读0次
- (void)Action:(UIPanGestureRecognizer *)recognizer {
    CGPoint translationPoint = [recognizer translationInView:self.view];
    CGPoint center = recognizer.view.center;
    recognizer.view.center = CGPointMake(center.x + translationPoint.x, center.y + translationPoint.y);
    [recognizer setTranslation:CGPointZero inView:self.view];
}
UIPanGestureRecognizer* ges = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(Action:)];
    gesture.minimumNumberOfTouches = 1;
    gesture.maximumNumberOfTouches = 1;
    [btn addGestureRecognizer:ges];

相关文章

网友评论

      本文标题:iOS 实现可拖动button

      本文链接:https://www.haomeiwen.com/subject/lfhkphtx.html