为了账号安全,请及时绑定邮箱和手机立即绑定

求指教关于手指按下松开或者移出到按钮的外部调用stop方法

求指教关于手指按下松开或者移出到按钮的外部调用stop方法

智慧大石 2023-04-27 14:10:05
我写了在Controller中自己定义了一个UIButton,绑定了一个事件UIControlEventTouchUpInside,然后在运行的时候,手指按下不松开,慢慢到按钮外部,按钮的UIControlEventTouchUpInside这个事件不执行。由于需求需要在手指移到按钮外部的时候执行UIControlEventTouchUpInside绑定的事件,所以我又给把这个方法绑定到这个按钮的UIControlEventTouchDragExit上,但这个事件出现了一个很让人郁闷的问题,当移出按钮外后一段距离了, 它才开始执行,请问我想让这个按钮在手指移出或者按下松开执行事件该怎么做?贴出来写的代码,_publishBtn = [[UIButton alloc] init];    float publishWith = (self.view.frame.size.width - 205)/2;     _publishBtn.frame = CGRectMake(publishWith, 344, 205, 47);     _publishBtn.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"btn.png"]];     [_publishBtn.titleLabel setTextColor:[UIColor blackColor]];     [_publishBtn setTitle:@"按住" forState:UIControlStateNormal];     _publishBtn.titleLabel.shadowColor = [UIColor blackColor];     _publishBtn.titleLabel.shadowOffset = CGSizeMake(0, 1.0);     [_publishBtn setTitle:@"松开" forState:UIControlStateHighlighted];     [_publishBtn setBackgroundImage:[UIImage imageNamed:@"btn_on.png"] forState:UIControlStateHighlighted];     [_publishBtn addTarget:self action:@selector(stop) forControlEvents:UIControlEventTouchUpInside];     [_publishBtn addTarget:self action:@selector(stop) forControlEvents:UIControlEventTouchDragExit];     [_publishBtn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchDown];     [self.view addSubview:_publishBtn];
查看完整描述

1 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

UIControlEventTouchUpOutside

这个在手指松开就执行的,但是移出边界后就不执行的。你是想移出到按钮之外响应这个事件,看看别的event可以不,如果不行,你用个view来替代吧。

查看完整回答
反对 回复 2023-04-29
  • 1 回答
  • 0 关注
  • 99 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信