开发者

When you select Cell, UITableViewCell to change the size of the Cell

开发者 https://www.devze.com 2023-01-06 03:26 出处:网络
I want to change the size of the selected cell. But, they shift position of the touch cell. -(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

I want to change the size of the selected cell. But, they shift position of the touch cell.

-       (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *currentCell = [aTableView cellForRowAtIndexPath:inde开发者_开发知识库xPath];

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:currentCell];
[UIView setAnimationDidStopSelector:@selector(endAnimation)];

float extendedSize = currentCell.frame.size.height;
currentCell.frame = CGRectMake(currentCell.frame.origin.x, currentCell.frame.origin.y, currentCell.frame.size.width, currentCell.frame.size.height + extendedSize);

UITableViewCell *afterCell;
for (int i=indexPath.row+1; i<=[aTableView numberOfRowsInSection:indexPath.section]; i++) {
    afterCell = [aTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]];
    afterCell.frame = CGRectMake(afterCell.frame.origin.x, (afterCell.frame.origin.y + extendedSize), afterCell.frame.size.width, afterCell.frame.size.height);
}
[UIView commitAnimations];
}

Thank you.


Just a simple example, but you'll get the idea:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView beginUpdates];
    [tableView endUpdates];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath isEqual:[tableView indexPathForSelectedRow]]) {
        return 88.0;
    }

    return 44.0;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消