gpt4 book ai didi

uitableview - 当使用 AutoLayout 和 UITableView 的动画大小时,避免 UITableViewCell 内容的动画

转载 作者:行者123 更新时间:2023-12-04 02:59:32 27 4
gpt4 key购买 nike

最初我有一个 UITableView,它只占用屏幕的一小部分,使用 AutoLayout 约束。 UITableViewCells 布局很好——它们非常基本,只有一个橙色的左对齐标签和一个黑色的右对齐标签。

现在,如果我在 UITableView 上向上滑动,它会进行动画处理(AutoLayout 约束),以占据屏幕的更大部分,同时重新加载表格并将额外的 UITableViewCells 带入场景。

我的问题是,新 UITableViewCells 的布局随着 UITableView 的大小调整而动画化。黑色右标签紧跟在橙色标签之后,并向右移动。最后,一切都按预期对齐,只是我不明白为什么当单元格出现在屏幕上时,黑色右标签不是简单地放在最右边,而是动画到位。

有没有办法告诉 UITableViewCell 立即根据 UITableView 的宽度和指定的 AutoLayout 约束来布局它的内容,从而绕过 UITableViewCell 内容的动画?

我创建 UITableViewCell 的代码如下所示:

- (instancetype)init
{
self = [super init];
if (self) {
self.textLabel = [[UILabel alloc]init];
self.textLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.textLabel.font = [UIFont boldSystemFontOfSize:16.0];
self.textLabel.textColor = [UIColor orangeColor];
[self.contentView addSubview:self.textLabel];

self.amountLabel = [[UILabel alloc]init];
self.amountLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.amountLabel.textAlignment = NSTextAlignmentRight;
self.amountLabel.font = [UIFont boldSystemFontOfSize:16.0];
[self.contentView addSubview:self.amountLabel];


NSDictionary *views = @{@"textLabel": self.textLabel, @"amountLabel": self.amountLabel};
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-10-[textLabel]-10-[amountLabel]-10-|" options:0 metrics:nil views:views]];
}
return self;
}

动画前的初始 TableView:

enter image description here

动画期间的 TableView(在向右的旅程中间带有黑色右侧标签):

enter image description here

最佳答案

以下代码适用于我。我在 detailTextLabel 和 TableView 的属性检查器中添加了第二个标签,我选择了样式为“Right Detail”。我附上了带有属性检查器的 tableview 的屏幕截图。

enter image description here

enter image description here

 cell.textLabel!.text = arrayLabel[indexPath.row]
cell.detailTextLabel!.text = cntarray[indexPath.row]

希望它可能对你有帮助。

关于uitableview - 当使用 AutoLayout 和 UITableView 的动画大小时,避免 UITableViewCell 内容的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27985943/

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