Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. -(IBAction)longPressGestureRecognized:(id)sender {
  2.  
  3. UILongPressGestureRecognizer *longPress = (UILongPressGestureRecognizer *)sender;
  4. UIGestureRecognizerState state = longPress.state;
  5.  
  6. CGPoint location = [longPress locationInView:self.collectionView];
  7. NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];
  8.  
  9. static UIView *snapshot = nil;
  10. static NSIndexPath *sourceIndexPath = nil;
  11.  
  12. switch (state) {
  13. case UIGestureRecognizerStateBegan: {
  14. if (indexPath) {
  15. sourceIndexPath = indexPath;
  16.  
  17. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
  18.  
  19. snapshot = [self customSnapshotFromView:cell];
  20.  
  21. CGPoint center = cell.center;
  22. snapshot.center = center;
  23. snapshot.alpha = 0.0;
  24. [self.collectionView addSubview:snapshot];
  25. [UIView animateWithDuration:0.25 animations:^{
  26.  
  27.  
  28. snapshot.center = center;
  29. snapshot.transform = CGAffineTransformMakeScale(1.05, 1.05);
  30. snapshot.alpha = 0.98;
  31.  
  32. cell.hidden = YES;
  33. } completion:nil];
  34. }
  35. break;
  36. }
  37. case UIGestureRecognizerStateChanged: {
  38. CGPoint center = snapshot.center;
  39. center.y = location.y;
  40. snapshot.center = center;
  41.  
  42. if (indexPath && ![indexPath isEqual:sourceIndexPath]) {
  43. [people2 exchangeObjectAtIndex:indexPath.row withObjectAtIndex:sourceIndexPath.row];
  44. [self.collectionView moveItemAtIndexPath:sourceIndexPath toIndexPath:indexPath];
  45. sourceIndexPath = indexPath;
  46. }
  47. break;
  48. }
  49. default: {
  50. UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:sourceIndexPath];
  51. [UIView animateWithDuration:0.25 animations:^{
  52.  
  53. snapshot.center = cell.center;
  54. snapshot.transform = CGAffineTransformIdentity;
  55. snapshot.alpha = 0.0;
  56. cell.hidden = NO;
  57.  
  58. } completion:^(BOOL finished){
  59. [snapshot removeFromSuperview];
  60. snapshot = nil;
  61.  
  62.  
  63.  
  64. }];
  65. sourceIndexPath = nil;
  66. break;
  67. }
  68. }
  69.  
  70. -(void)handleReload:(NSNotification *)notification {
  71. NSLog(@"Notification Recieved");
  72. people2 = [databaseClass getData];
  73. [self.collectionView reloadData];
  74.  
  75. +(NSMutableArray*)getData {
  76. [self databaseInit];
  77.  
  78. peopleArray = [[NSMutableArray alloc] init];
  79.  
  80. if (sqlite3_open(dbpath, &peopleDB)== SQLITE_OK)
  81. {
  82.  
  83. NSString *selectSQL = @"SELECT ID, NAME, POINTS, COLOUR FROM PEOPLE";
  84. sqlite3_prepare_v2(peopleDB,[selectSQL UTF8String],-1,&statement,NULL);
  85.  
  86. while (sqlite3_step(statement)== SQLITE_ROW)
  87. {
  88. PersonObject *newPerson = [[PersonObject alloc]init];
  89. newPerson.ID = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]integerValue];
  90. newPerson.name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
  91. newPerson.points = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)] integerValue];
  92. newPerson.colour = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
  93. [peopleArray addObject:newPerson];
  94.  
  95. }
  96.  
  97. }
  98.  
  99. sqlite3_finalize(statement);
  100. sqlite3_close(peopleDB);
  101.  
  102. return peopleArray;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement