佚名通过本文主要向大家介绍了后松开,同时亮起后松开,指示灯同时亮起后松开,灯同时亮起后松开,起后松开等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: iOS- UIButton按住后松开不执行UIControlEventTouchUpInside
描述:
解决方案1:
描述:
打算实现一个长按录音,松开完成并结束的效果。
但是现在在触发了UIControlEventTouchDown之后,松手的时候UIControlEventTouchUpInside并没有被触发,这是为什么?
相关部分代码:
[self.voiceSignView.voiceButton addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
[self.voiceSignView.voiceButton addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside];
-(void)touchDown:(UIButton *)button
{
DLog(@"长按触发");
}
-(void)touchUpInside:(UIButton *)button
{
DLog(@"长按结束");
}
解决方案1:
多看文档
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(0, 0, 200, 80)];
[button setTitle:@"button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonAction:forEvent:) forControlEvents:UIControlEventAllTouchEvents];
[self.view addSubview:button];
- (void)buttonAction:(id)sender forEvent:(UIEvent *)event{
UITouchPhase phase = event.allTouches.anyObject.phase;
if (phase == UITouchPhaseBegan) {
NSLog(@"press");
}
else if(phase == UITouchPhaseEnded){
NSLog(@"release");
}
}