UITableView長按手勢UILongPressGestureRecognizer
作者:佚名
給UITableView 添加長按手勢,識別長按哪一行,按手勢類UILongPressGestureRecognizer,屬minimumPressDuration表示最短長按的時間.
給UITableView 添加長按手勢,識別長按哪一行。
長按手勢類UILongPressGestureRecognizer, 屬性minimumPressDuration表示最短長按的時間
添加手勢代碼:
- UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
- longPressGr.minimumPressDuration = 1.0;
- [self.tableView addGestureRecognizer:longPressGr];
- [longPressGr release];
響應長按事件代碼:
- -(void)longPressToDo:(UILongPressGestureRecognizer *)gesture
- {
- if(gesture.state == UIGestureRecognizerStateBegan)
- {
- CGPoint point = [gesture locationInView:self.tableView];
- NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:point];
- if(indexPath == nil) return ;
- //add your code here
- }
- }
責任編輯:閆佳明
來源:
oschina