如何使按钮只能单击一次或长按后才触发点击事件?
如何使按钮只能单击一次或长按后才触发点击事件?
请检查这段代码
//Add Long Press Gesture Reconizer
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 3; //seconds
longPress.delegate = self;
[yourButton addGestureRecognizer:longPress];
//Add button touch
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
[yourButton addGestureRecognizer:tapGesture];
//For touch you can also set selector for button event with Controlevent touchupinside
-(void) handleLongPress : (id)sender
{
//Long Press done by the user
}
-(void) tapDetected : (id) sender
{
//Button Tapped by user
}