Can you animate a height change on a UITableViewCell when selected?

前端 未结 21 1028
天涯浪人
天涯浪人 2020-11-22 04:41

I\'m using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular pers

21条回答
  •  别跟我提以往
    2020-11-22 04:59

    Yes It's Possible.

    UITableView has a delegate method didSelectRowAtIndexPath

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [UIView animateWithDuration:.6
                              delay:0
             usingSpringWithDamping:UIViewAnimationOptionBeginFromCurrentState
              initialSpringVelocity:0
                            options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    
                                cellindex = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
                                NSArray* indexArray = [NSArray arrayWithObjects:indexPath, nil];
                                [violatedTableView beginUpdates];
                                [violatedTableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];
                                [violatedTableView endUpdates];
                            }
                         completion:^(BOOL finished) {
        }];
    }
    

    But in your case if the user scrolls and selects a different cell then u need to have the last selected cell to shrink and expand the currently selected cell reloadRowsAtIndexPaths: calls heightForRowAtIndexPath: so handle accordingly.

提交回复
热议问题