فهرست منبع

Add Swipe Gesture Direction Right for editing tableview

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Pierre SAGASPE 11 سال پیش
والد
کامیت
967e318e5c
1فایلهای تغییر یافته به همراه18 افزوده شده و 0 حذف شده
  1. 18 0
      Sources/VLCPlaylistViewController.m

+ 18 - 0
Sources/VLCPlaylistViewController.m

@@ -400,6 +400,10 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
     if (cell == nil)
         cell = [VLCPlaylistTableViewCell cellWithReuseIdentifier:CellIdentifier];
 
+    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightGestureAction:)];
+    [swipeRight setDirection:(UISwipeGestureRecognizerDirectionRight)];
+    [cell addGestureRecognizer:swipeRight];
+
     NSInteger row = indexPath.row;
     cell.mediaObject = _foundMedia[row];
 
@@ -471,6 +475,20 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
     [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  }
 
+- (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
+{
+    if ([[self.editButtonItem title] isEqualToString:NSLocalizedString(@"BUTTON_CANCEL",@"")])
+        [self setEditing:NO animated:YES];
+    else {
+        [self setEditing:YES animated:YES];
+
+        NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
+        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:path.row inSection:path.section]
+                                    animated:YES
+                              scrollPosition:UITableViewScrollPositionNone];
+    }
+}
+
 #pragma mark - Collection View
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
 {