首页 > iOS- UIButton按住后松开不执行UIControlEventTouchUpInside

iOS- UIButton按住后松开不执行UIControlEventTouchUpInside

打算实现一个长按录音,松开完成并结束的效果。
但是现在在触发了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(@"长按结束");
    
    

}

多看文档

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");
    }
}
【热门文章】
【热门文章】