2011-03-15 2 views
9

between 2 table views을 복사해야합니다.펄스 응용 프로그램으로 테이블간에 셀을 복사하는 방법

나는 더 많은 또는 덜 효과적인 해결책이 있습니다. 그러나 부드럽 지 않아 pulse app 주문 순서 옵션과 유사하게 처리하고 싶습니다.

펄스가 작동하는 방식에 특별한 점은 재주문 애니메이션이 일반적인 재주문과 동일하다는 것입니다. 여전히 셀은 테이블 사이를 이동할 수 있습니다.

- (BoardColumnView *) addColumn:(NSString *)title type:(ColumnType)type{ 
    BoardColumnView *col = [BoardColumnView createColumn:title]; 

    [self.columns addObject:col]; 

    // Add a pinch gesture recognizer to the table view. 
    UILongPressGestureRecognizer* draggingRecognizer = [[UILongPressGestureRecognizer alloc] 
                initWithTarget:self 
                action:@selector(moveActionGestureRecognizerStateChanged:) 
                ]; 

    draggingRecognizer.minimumPressDuration = 0.5; 
    draggingRecognizer.delegate = self; 

    [col.tableView addGestureRecognizer:draggingRecognizer]; 
    [draggingRecognizer release]; 


    return col; 
} 

#pragma mark - 
#pragma mark UIGestureRecognizer Delegate/Actions 

- (BOOL) gestureRecognizerShouldBegin: (UIGestureRecognizer *) gestureRecognizer 
{ 
    ALog(@"Drag detected"); 
    return YES; 
} 

- (void) moveActionGestureRecognizerStateChanged: (UIGestureRecognizer *) recognizer 
{ 
    switch (recognizer.state) 
    { 
     default: 
     case UIGestureRecognizerStateFailed: 
      // do nothing 
      break; 

     case UIGestureRecognizerStatePossible: 
     case UIGestureRecognizerStateCancelled: 
     { 
      ALog(@"Canceled"); 

      [UIView beginAnimations: @"SnapBack" context: NULL]; 
      [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
      [UIView setAnimationDuration: 0.5]; 
      [UIView setAnimationDelegate: self]; 
      [UIView setAnimationDidStopSelector: @selector(finishedSnap:finished:context:)]; 

      CGRect f = self.dragView.frame; 
      f.origin = _dragOriginCellOrigin; 
      self.dragView.frame = f; 

      [UIView commitAnimations]; 

      break; 
     } 
     case UIGestureRecognizerStateEnded: 
     { 
      // move the real cell into place 
      [UIView beginAnimations: @"SnapToPlace" context: NULL]; 
      [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
      [UIView setAnimationDuration: 0.5]; 
      [UIView setAnimationDelegate: self]; 
      [UIView setAnimationDidStopSelector: @selector(finishedSnap:finished:context:)]; 

      CGRect r = self.dragView.frame;//[self.content rectForItemAtIndex: _emptyCellIndex]; 
      CGRect f = self.dragView.frame; 
      f.origin.x = r.origin.x + floorf((r.size.width - f.size.width) * 0.5); 
      f.origin.y = r.origin.y + floorf((r.size.height - f.size.height) * 0.5); 
      NSLog(@"Gesture ended-- moving to %@", NSStringFromCGRect(f)); 
      self.dragView.frame = f; 

      self.dragView.transform = CGAffineTransformIdentity; 
      self.dragView.alpha = 1.0; 

      [UIView commitAnimations]; 
      break; 
     } 

     case UIGestureRecognizerStateBegan: 
     {   
      ALog(@"Start move.."); 
      // find the cell at the current point and copy it into our main view, applying some transforms 
      _lastColumn = (BoardColumnView *)[(UITableView *)recognizer.view superview]; 
      _targetColumn = _lastColumn; 

      if (_lastIndexPath) { 
       [_lastIndexPath release]; 
       _lastIndexPath = nil; 
      } 

      _lastIndexPath = [_lastColumn.tableView indexPathForRowAtPoint:[recognizer locationInView: _lastColumn]]; 

      UITableViewCell *sourceCell = [_lastColumn.tableView cellForRowAtIndexPath:_lastIndexPath]; 

      CGRect frame = [_lastColumn convertRect: sourceCell.frame fromView: self.content]; 

      self.dragView = [[[UIImageView alloc] initWithImage:[sourceCell screenshot]] autorelease]; 
      self.dragView.opaque = YES; 
      self.dragView.backgroundColor = _lastColumn.backgroundColor; 

      self.dragView.center = [recognizer locationInView: self.view]; 
      //self.dragView.cornerRadius = 8; // if you like rounded corners 
      self.dragView.layer.shadowOffset = CGSizeMake(-5, 2); 
      self.dragView.layer.shadowRadius = 5; 
      self.dragView.layer.shadowOpacity = 0.5; 

      [content addSubview: self.dragView]; 

      [content bringSubviewToFront:self.dragView]; 
      // grab some info about the origin of this cell 
      _dragOriginCellOrigin = frame.origin; 

      [UIView beginAnimations: @"" context: NULL]; 
      [UIView setAnimationDuration: 0.2]; 
      [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 

      // transformation-- larger, slightly transparent 
      self.dragView.transform = CGAffineTransformMakeScale(1.2, 1.2); 
      self.dragView.alpha = 0.7; 

      [UIView commitAnimations]; 

      /* // reload the grid underneath to get the empty cell in place 
      [self.content reloadItemsAtIndices: [NSIndexSet indexSetWithIndex: index] 
           withAnimation: AQGridViewItemAnimationNone]; 
      */ 
      break; 
     } 

     case UIGestureRecognizerStateChanged: 
     { 
      // update draging cell location 
      self.dragView.center = [recognizer locationInView: self.view]; 

      //Determinar sobre que columna esta flotando.. 
      CGRect global; 

      if (_targetColumn) { 
       _targetColumn = nil; 
      } 
      for (BoardColumnView *col in self.columns) { 
       UITableView *table = col.tableView; 
       global = [table convertRect:self.dragView.frame fromView:content]; 

       if ([table pointInside:global.origin withEvent:nil]) { 
        ALog([NSString stringWithFormat: @"Esta sobre la tabla %@", col.column.name]); 
        _targetColumn = col; 
        break; 
       } 
      } 

      if (!_targetColumn) 
      {     
       ALog(@"Esta en zona muerta"); 
      } 

      break; 
     } 
    } 
} 

- (void) finishedSnap: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context 
{  
    if (_targetColumn && _lastIndexPath) {  
     ALog(@"Moviendo a nuevo destino"); 

     CGRect frame = [_targetColumn convertRect: self.dragView.frame fromView: self.content];  
     NSIndexPath *destPath = [_targetColumn.tableView indexPathForRowAtPoint: frame.origin]; 

     [UIView beginAnimations: @"" context: NULL]; 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

     self.dragView.backgroundColor = _targetColumn.backgroundColor; 

     //Si inserta entre tareas en destino... 

     _lastColumn.totalRows -= 1; 
     _targetColumn.totalRows += 1; 

     [_lastColumn.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:_lastIndexPath] withRowAnimation:UITableViewRowAnimationTop]; 

     if (destPath) {   
      [_targetColumn.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:destPath] withRowAnimation:UITableViewRowAnimationBottom]; 
     } else { 
      [_targetColumn.tableView reloadData]; 
     } 



     [UIView commitAnimations]; 
    } else {   
     ALog(@"Cancelado el moviento, regresar a home"); 

     UITableViewCell * sourceCell = [_lastColumn.tableView cellForRowAtIndexPath:_lastIndexPath];   
     if (sourceCell) { 

      [UIView beginAnimations: @"Back" context: NULL]; 
      [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
      [UIView setAnimationDuration: 0.5]; 
      [UIView setAnimationDelegate:self]; 
      [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 

      //self.dragView.transform = CGAffineTransformIdentity; 
      self.dragView.frame = [self.content convertRect: sourceCell.frame fromView: _lastColumn]; 
      //self.dragView.alpha = 0.0; 

      [UIView commitAnimations];  
     } 
    } 
} 

- (void)animationDidStop:(id)animationID finished:(BOOL)flag context:(id)context { 
    // dismiss our copy of the cell 
    ALog(@"Eliminando drag view"); 
    [self.dragView removeFromSuperview]; 
    self.dragView = nil; 

    _lastColumn = nil; 
    _targetColumn = nil; 

    if (_lastIndexPath) { 
     _lastIndexPath = nil; 
    } 
} 

UPDATE : 지금까지 내 진행 상황을 표시하는 오픈 소스 프로젝트를 만들었습니다

내가 지금 가지고있는 것입니다

https://bitbucket.org/elmalabarista/dragdroptableviews

+0

비슷한 펄스 응용 프로그램에 대한이 자습서를 읽는 것이 좋습니다. http://www.raywenderlich.com/4680/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app -part-1 http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2 그리고 이것은 OpenSource입니다. http://www.raywenderlich.com/downloads/HorizontalTables2.zip 즐기십시오! –

+0

[ipad : UITableViewCell을 하나의 UITableViewController에서 드래그하여 다른 것으로 끌어다 놓기] (http://stackoverflow.com/questions/6506946/ipad-drag-a-uitableviewcell-from-one-uitableviewcontroller-and-drop- 그것으로 ano에) – CodaFi

답변

관련 문제