UILongPressGestureRecognizer
- это то, что вам нужно.Например,
UILongPressGestureRecognizer *longPress_gr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(doAction:)];
[longPress_gr setMinimumPressDuration:2]; // triggers the action after 2 seconds of press
[yourButton addGestureRecognizer:longPress_gr];
Чтобы позволить вашему действию срабатывать только один раз (т. Е. По истечении 2 секунд), убедитесь, что ваш метод doAction:
выглядит примерно так:
- (void)doAction:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
// Your code here
}
}