今天做任务的时候遇到了UITableViewCell的长按处理,比如按住一秒之后触发事件。刚开始本想自定义cell,然后在里面捕捉touch事件,touchbegin后开始计时,超过一秒触发事件,不过想想如此有点麻烦,然后查下了orgnizer,发现了
UILongPressGestureRecogn
UILongPressGestureRecogn
initWithTarget:self action:@selector(handleLongPress:)];
longPressReger.minimumPressDuration = 1.0;
[myTableView addGestureRecognizer:longPressReger];
[longPressReger release];
-(void)handleLongPress:(UILongPressGestureRecogn
{
CGPoint point = [gestureRecognizer locationInView:myTableView];
if(gestureRecognizer.state == UIGestureRecognizerState
{
}
else if(gestureRecognizer.state == UIGestureRecognizerState
{
}
else if(gestureRecognizer.state == UIGestureRecognizerState
{
}
NSIndexPath *indexPath = [myTableView indexPathForRowAtPoint:point];
if (indexPath == nil)
NSLog(@”not tableView”);
else
{
focusRow = [indexPath row];
focusView.hidden = NO;
}
}