iOS- UIButton按住后松开不执行UIControlEventTouchUpInside
bwin官网
bwin官网
当前位置 : bwin官网 > bwin必赢亚洲注册

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

打算实现一个长按录音,松开完成并结束的效果。
但是现在在触发了UIControlEventTouchDown之后,松手的时候UIControlEventTouchUpInside并没有被触发,这是为什么?

相关部分代码:

[self.voiceSignView.voiceButton addTarget:self action:@selectortouchDown: forControlEvents:UIControlEventTouchDown];
[self.voiceSignView.voiceButton addTarget:self action:@selectortouchUpInside: forControlEvents:UIControlEventTouchUpInside];

-voidtouchDown:UIButton *button
{
    DLog@"长按触发";
    
    

}


-voidtouchUpInside:UIButton *button
{
    DLog@"长按结束";
    
    

}

这个问题已被关闭,原因:已解决

多看文档

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake0, 0, 200, 80];
[button setTitle:@"button" forState:UIControlStateNormal];
[button addTarget:self action:@selectorbuttonAction:forEvent: forControlEvents:UIControlEventAllTouchEvents];
[self.view addSubview:button];
    
- voidbuttonAction:idsender forEvent:UIEvent *event{
    UITouchPhase phase = event.allTouches.anyObject.phase;
    if phase == UITouchPhaseBegan {
        NSLog@"press";
    }
    else ifphase == UITouchPhaseEnded{
        NSLog@"release";
    }
}

栏目列表

广告位

bwin官网