UITableView長(zhǎng)按手勢(shì)UILongPressGestureRecognizer
作者:佚名
給UITableView 添加長(zhǎng)按手勢(shì),識(shí)別長(zhǎng)按哪一行,按手勢(shì)類UILongPressGestureRecognizer,屬minimumPressDuration表示最短長(zhǎng)按的時(shí)間.
給UITableView 添加長(zhǎng)按手勢(shì),識(shí)別長(zhǎng)按哪一行。
長(zhǎng)按手勢(shì)類UILongPressGestureRecognizer, 屬性minimumPressDuration表示最短長(zhǎng)按的時(shí)間
添加手勢(shì)代碼:
- UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressToDo:)];
- longPressGr.minimumPressDuration = 1.0;
- [self.tableView addGestureRecognizer:longPressGr];
- [longPressGr release];
響應(yīng)長(zhǎng)按事件代碼:
- -(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
- }
- }
責(zé)任編輯:閆佳明
來源:
oschina