iOS 添加长按手势
程序员文章站
2024-03-24 14:47:58
...
创建手势
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
///设置长按手势最小按压时间
longPress.minimumPressDuration = 2;
[self.view addGestureRecognizer:longPress];
响应方法
- (void)longPress:(UIGestureRecognizer *)gesture
{
/// 在手势开始时进行相关操作
if (gesture.state == UIGestureRecognizerStateBegan) {
NSLog(@"在这里进行长按手势响应");
}
}