Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Last active August 29, 2015 14:13
Show Gist options
  • Save odrobnik/40af322e3b2fa3bbfb27 to your computer and use it in GitHub Desktop.
Save odrobnik/40af322e3b2fa3bbfb27 to your computer and use it in GitHub Desktop.
Workaround for rdar://19411256
//
// PLYTableView.m
// ProdlyApp
//
// Created by Oliver Drobnik on 08/01/15.
// Copyright (c) 2015 ProductLayer. All rights reserved.
//
#import "PLYTableView.h"
@interface PLYTableView () <UIGestureRecognizerDelegate>
@end
@implementation PLYTableView
- (void)awakeFromNib
{
[super awakeFromNib];
[self _commonSetup];
}
- (void)_commonSetup
{
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handlePan:)];
pan.delegate = self;
[self addGestureRecognizer:pan];
}
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
// always recognize parallel to every other recognizer
return YES;
}
#pragma mark - Actions
- (void)_handlePan:(UIPanGestureRecognizer *)gesture
{
switch (gesture.state)
{
default:
{
break;
}
case UIGestureRecognizerStateFailed:
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateEnded:
{
BOOL forceClose = NO;
for (UITableViewCell *cell in self.visibleCells)
{
CGPoint cellPoint = [self convertPoint:CGPointZero fromView:cell];
if (cellPoint.x < 0)
{
NSIndexPath *indexPath = [self indexPathForCell:cell];
NSArray *actions = [self.delegate tableView:self editActionsForRowAtIndexPath:indexPath];
CGFloat widthOfActions = 80.0*[actions count];
if (cellPoint.x > -widthOfActions/2.0)
{
NSLog(@"will close");
// not enough open to stay open
forceClose = YES;
break;
}
}
}
if (forceClose)
{
[self setEditing:NO animated:YES];
}
break;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment