Swipe to delete implemented

This commit is contained in:
Joyce Yan 2015-01-23 17:26:04 -10:00 committed by Frederic Jacobs
parent b494b71dbc
commit d740f801c6
3 changed files with 7 additions and 30 deletions

View File

@ -19,7 +19,6 @@ typedef enum : NSUInteger {
@class InboxTableViewCell;
@protocol TableViewCellDelegate <NSObject>
- (void)tableViewCellTappedDelete:(InboxTableViewCell *)cell;
- (void)tableViewCellTappedArchive:(InboxTableViewCell *)cell;
@end

View File

@ -15,7 +15,7 @@
#define DELETE_IMAGE_VIEW_WIDTH 19.0f
#define TIME_LABEL_SIZE 11
#define DATE_LABEL_SIZE 13
#define SWIPE_ARCHIVE_OFFSET -50
@implementation InboxTableViewCell
@ -195,39 +195,17 @@
_archiveImageView.bounds.size.height);
}
if (scrollView.contentOffset.x > CGRectGetWidth(_archiveView.frame)*2) {
_deleteImageView.image = [_deleteImageView.image jsq_imageMaskedWithColor:[UIColor ows_redColor]];
_deleteImageView.bounds = CGRectMake(_deleteImageView.bounds.origin.x,
_deleteImageView.bounds.origin.y,
DELETE_IMAGE_VIEW_WIDTH,
_deleteImageView.bounds.size.height);
} else {
_deleteImageView.image = [_deleteImageView.image jsq_imageMaskedWithColor:[UIColor ows_darkGrayColor]];
double ratio = _scrollView.contentOffset.x / (CGRectGetWidth(_deleteView.frame)*2);
double newWidth = DELETE_IMAGE_VIEW_WIDTH/2.0f + (DELETE_IMAGE_VIEW_WIDTH * ratio)/2.0f;
_deleteImageView.bounds = CGRectMake(_deleteImageView.bounds.origin.x,
_deleteImageView.bounds.origin.y,
(CGFloat)newWidth,
_deleteImageView.bounds.size.height);
}
}
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset {
if (_scrollView.contentOffset.x < 0) {
if (_scrollView.contentOffset.x < SWIPE_ARCHIVE_OFFSET) {
// archive the thread
[_delegate tableViewCellTappedArchive:self];
} else {
*targetContentOffset = CGPointMake(CGRectGetWidth(_archiveView.frame), 0);
}
if (scrollView.contentOffset.x > CGRectGetWidth(_archiveView.frame)/4) {
[_delegate tableViewCellTappedDelete:self];
} else {
// don't do anything
*targetContentOffset = CGPointMake(CGRectGetWidth(_archiveView.frame), 0);
}
}

View File

@ -104,7 +104,7 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
}
#pragma mark - Table view data source
#pragma mark - Table View Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return (NSInteger)[self.threadMappings numberOfSections];
@ -168,8 +168,8 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
#pragma mark - HomeFeedTableViewCellDelegate
- (void)tableViewCellTappedDelete:(InboxTableViewCell*)cell {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
- (void)tableViewCellTappedDelete:(NSIndexPath*)indexPath {
//NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
TSThread *thread = [self threadForIndexPath:indexPath];
if([thread isKindOfClass:[TSGroupThread class]]) {
DDLogDebug(@"leaving the group");