Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions JTGestureBasedTableView/JTTableViewGestureRecognizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ @interface JTTableViewGestureRecognizer () <UIGestureRecognizerDelegate>
@property (nonatomic, strong) UIPinchGestureRecognizer *pinchRecognizer;
@property (nonatomic, strong) UIPanGestureRecognizer *panRecognizer;
@property (nonatomic, strong) UILongPressGestureRecognizer *longPressRecognizer;
@property (nonatomic, strong) UITapGestureRecognizer *tapGestureRecognizer;
@property (nonatomic, assign) JTTableViewGestureRecognizerState state;
@property (nonatomic, strong) UIImage *cellSnapshot;
@property (nonatomic, assign) CGFloat scrollingRate;
Expand All @@ -46,7 +47,7 @@ - (void)commitOrDiscardCell;
@implementation JTTableViewGestureRecognizer
@synthesize delegate, tableView, tableViewDelegate;
@synthesize addingIndexPath, startPinchingUpperPoint, addingRowHeight;
@synthesize pinchRecognizer, panRecognizer, longPressRecognizer;
@synthesize pinchRecognizer, panRecognizer, longPressRecognizer, tapGestureRecognizer;
@synthesize state, addingCellState;
@synthesize cellSnapshot, scrollingRate, movingTimer;

Expand Down Expand Up @@ -364,6 +365,22 @@ - (void)longPressGestureRecognizer:(UILongPressGestureRecognizer *)recognizer {
}
}

- (void) tapRecognizer:(UITapGestureRecognizer *) recognizer {
if(recognizer.state == UIGestureRecognizerStateRecognized){
CGPoint point = [recognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
if(!indexPath){
self.addingIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView beginUpdates];
[self.delegate gestureRecognizer:self needsAddRowAtIndexPath:self.addingIndexPath];
[self.tableView reloadData];
[self.delegate gestureRecognizer:self needsCommitRowAtIndexPath:self.addingIndexPath];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:self.addingIndexPath] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
}
}
}

#pragma mark UIGestureRecognizer

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
Expand Down Expand Up @@ -523,6 +540,10 @@ - (BOOL)respondsToSelector:(SEL)aSelector {
#pragma mark Class method

+ (JTTableViewGestureRecognizer *)gestureRecognizerWithTableView:(UITableView *)tableView delegate:(id)delegate {
tableView.clipsToBounds = NO;
UIView *new = [[UIView alloc] initWithFrame:CGRectMake(0, -40, 320, 40)];
[tableView addSubview:new];

JTTableViewGestureRecognizer *recognizer = [[JTTableViewGestureRecognizer alloc] init];
recognizer.delegate = (id)delegate;
recognizer.tableView = tableView;
Expand All @@ -543,7 +564,13 @@ + (JTTableViewGestureRecognizer *)gestureRecognizerWithTableView:(UITableView *)
[tableView addGestureRecognizer:longPress];
longPress.delegate = recognizer;
recognizer.longPressRecognizer = longPress;


UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:recognizer
action:@selector(tapRecognizer:)];
[tableView addGestureRecognizer:tap];
tap.delegate = recognizer;
recognizer.tapGestureRecognizer = tap;

return recognizer;
}

Expand Down
2 changes: 1 addition & 1 deletion JTGestureBasedTableViewDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ - (void)gestureRecognizer:(JTTableViewGestureRecognizer *)gestureRecognizer need
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
// Return to list
}
else {
else if([cell respondsToSelector:@selector(setFinishedHeight:)]){
cell.finishedHeight = NORMAL_CELL_FINISHING_HEIGHT;
cell.imageView.image = nil;
cell.textLabel.text = @"Just Added!";
Expand Down