您可以从创建UILongPressGestureRecognizer
实例并将其附加到按钮开始.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[self.button addGestureRecognizer:longPress];
[longPress release];
然后实现处理该手势的方法
- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
NSLog(@"Long Press");
}
}
现在,这将是基本的方法.您还可以设置印刷机的最短持续时间和可容忍的误差.还要注意,如果您在识别手势之后调用该方法几次,所以如果您想在它的末尾做一些事情,您将必须判断它的状态并处理它.