最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
ios可拖动按钮实例
时间:2022-06-26 05:48:35 编辑:袖梨 来源:一聚教程网
最近产品抽风,想做许鲜网的那个小客服按钮,虽然没啥难度,但是我懒啊,哈哈,上度娘搞了一个,但是点击事件和拖动重复了,擦。干脆写一个吧,仅供参考。
话不多说,上代码:
- (UIButton *)panButton {
if (!_panButton) {
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
_panButton = [[UIButton alloc] init];
_panButton.backgroundColor = [UIColor blueColor];
_panButton.layer.border.f;
_panButton.layer.borderColor = [UIColor greenColor].CGColor;
[_panButton setTitle:@"清除缓存" forState:UIControlStateNormal];
_panButton.titleLabel.font = [UIFont systemFontOfSize:9];
[_panButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[_panButton addGestureRecognizer:panGesture];
}
return _panButton;
}
- (void)panAction:(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];
}
-(void)buttonAction:(UIButton *)sender
{
NSLog(@"烦人,点我干啥~");
}
相关文章
- 学信网官方登录入口-个人学历学位认证查询系统 12-20
- 原神AKT资源站网页入口-AKT原神官网链接直达地址 12-20
- CET4准考证成绩防伪验证官方入口-CET4准考证成绩下载快速指南入口 12-20
- yandex网站突然打不开-俄罗斯搜索引擎最新可用入口2025 12-20
- cet4成绩快速查询入口-cet4成绩官方查询入口官网 12-20
- 抖币充值官网入口-抖币充值官网入口1:10 12-20