UITableViewCell 的长按事件处理

今天做任务的时候遇到了UITableViewCell的长按处理,比如按住一秒之后触发事件。刚开始本想自定义cell,然后在里面捕捉touch事件,touchbegin后开始计时,超过一秒触发事件,不过想想如此有点麻烦,然后查下了orgnizer,发现了

UILongPressGestureRecognizer这个类,嘿嘿,确实是我需要的,然后查看文档,发现其可以支持多指长按,不过这里我需要单指就可以了。使用方法也比较方便,大家直接参考代码就可以了:

UILongPressGestureRecognizer *longPressReger = [[UILongPressGestureRecognizer alloc]

initWithTarget:self action:@selector(handleLongPress:)];

longPressReger.minimumPressDuration = 1.0;

[myTableView addGestureRecognizer:longPressReger];

[longPressReger release];

 

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer

{

CGPoint point = [gestureRecognizer locationInView:myTableView];

 

if(gestureRecognizer.state == UIGestureRecognizerStateBegan)

{

}

else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)

{

}

else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)

{

}

NSIndexPath *indexPath = [myTableView indexPathForRowAtPoint:point];

if (indexPath == nil)

NSLog(@”not tableView”);

else

{

focusRow = [indexPath row];

focusView.hidden = NO;

}

}

转载于:https://www.cnblogs.com/tongdengquan/archive/2012/05/24/6090546.html

你可能感兴趣的:(UITableViewCell 的长按事件处理)