problems with animation when deleting the last row of a TableView in ios7

前端 未结 4 948
陌清茗
陌清茗 2020-12-16 17:04

I\'m having some issues when deleting the last row of my (only) section in my tableView. Any other row works fine, but if I delete the row at the bottom of my <

相关标签:
4条回答
  • 2020-12-16 17:17

    I had the same bug. I just changed the animation type on UITableViewRowAnimationMiddle, and it fixed it all.

    0 讨论(0)
  • 2020-12-16 17:22

    Here is a solution I found to work well that builds upon jaydee3's answer:

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    { 
         if (editingStyle == UITableViewCellEditingStyleDelete) {
              // hide cell, because animations are broken on ios7
              double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    
              if (iosVersion >= 7.0 && iosVersion <= 8.0) {
                  // Animating the cell's alpha change gives it a smooth transition
                  // Durations > .17 show the glitch on iPad, phone looks nice up to 0.3
                  [UIView animateWithDuration:0.17 animations:^(void) {
                      [tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
                  }];
              }
              NSArray *deleteIndexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];
    
              // UITableViewRowAnimationFade looks nice with the animation imho
              [tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade];
         }
    }
    
    0 讨论(0)
  • 2020-12-16 17:22

    My solution to this painful issue :)

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [UIView animateWithDuration:0.25f
                         animations:^{
    
                             UIScrollView *internalScrollView = (UIScrollView*)cell.contentView.superview;
                             if([internalScrollView isKindOfClass:[UIScrollView class]]){
    
                                 [internalScrollView setContentOffset:CGPointZero animated:YES];
                             }
    
                             cell.center = CGPointMake(cell.center.x - cell.bounds.size.width, cell.center.y);
    
                         } completion:^(BOOL finished) {
    
                             [self.rowModels removeObjectAtIndex:indexPath.row];
    
                             [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                         }];
    }
    
    0 讨论(0)
  • 2020-12-16 17:36

    Its a bug of ios7.. the tablerow animations are broken! My fix was to fadeOut the cell right before the tableViewRowAnimation..

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // hide cell, because animations are broken on ios7
        double iosVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
        if (iosVersion >= 7.0 && iosVersion <= 8.0) {
            [tableView cellForRowAtIndexPath:indexPath].alpha = 0.0;
        }
    
        [tableView deleteRowsAtIndexPaths:@[indexPath]
                         withRowAnimation:UITableViewRowAnimationMiddle];
    }
    
    0 讨论(0)
提交回复
热议问题