我写了在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];
守着一只汪