gpt4 book ai didi

iphone - 选择Cell时,UITableViewCell改变Cell的大小

转载 作者:太空狗 更新时间:2023-10-30 03:39:52 29 4
gpt4 key购买 nike

我想更改所选单元格的大小。但是,它们会移动触摸单元的位置。

-       (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *currentCell = [aTableView cellForRowAtIndexPath:indexPath];

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];
}

谢谢。

最佳答案

只是一个简单的例子,但你会明白的:

- (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;
}

关于iphone - 选择Cell时,UITableViewCell改变Cell的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3173789/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com