UILongPressGestureRecognizer * _longPress;
//长按手势
_longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
_longPress.minimumPressDuration = 0.2; //设置最小长按时间:默认为0.5秒
[self.view addGestureRecognizer:_longPress];
/**
* 处理长按手势
* @param gesture 点按手势识别器对象实例
*/
-(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
{
//长按开始
if (gesture.state == UIGestureRecognizerStateBegan) {
NSLog(@"--> 长按手势 state :begin ");
}else {
//长按结束
NSLog(@"--> 长按手势 state :end ");
}
}
本文介绍如何在iOS应用中实现长按手势识别。通过创建并配置UILongPressGestureRecognizer,可以自定义长按时长,并响应开始与结束状态。适用于希望增强用户交互体验的iOS开发者。
1103

被折叠的 条评论
为什么被折叠?



