【问题标题】:UITableViewCell Objects Are Misplaced When Being Rendered For the First TimeUITableViewCell 对象在第一次渲染时放错了位置
【发布时间】:2014-08-25 11:40:40
【问题描述】:

许多人可能已经注意到,有时当 UITableView 改变高度并因此显示新行时,这些行的内容会错位(例如当它们都位于行的中心或行的最左侧时或等等),当行显示时,它们会立即(动画)移动到正确的原始位置。谁能告诉我如何禁用这种动画?

谢谢


P.S:我知道我的描述不是很清楚,所以我录制了一个视频来说明发生了什么,可以从this link访问。 (链接已更新)

P.P.S:这也可以在 ViberWhatsapp 等其他消息应用程序中看到。我已经从ViberWhatsapp 录制了相同效果的视频,但必须有解决方案来禁用它,这显然是Line 所做的。

【问题讨论】:

  • 在您的 UITableView 委托方法 "CellForRowAtIndex...." 中,注释 if (cell==nil){ } 就像删除这两行代码, --> "if(cell == nil) {" 和 "}"
  • 你试过这个 - stackoverflow.com/questions/10040508/… 吗?
  • 亲爱的激进分子,我不明白它与我的问题有何关联
  • @akk 我做到了,但没有进展:(
  • @Unkn0wn.Bit 我也遇到了同样的问题,我也解决了。

标签: ios iphone uitableview animation


【解决方案1】:

这对我有用。例如,当第一次出现行数据时,它会以动画形式显示。

//这个函数是所有魔法发生的地方 - 在 rowForCellAtIndexPath 旁边调用

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if(![arrObjectsDone containsObject:[NSString stringWithFormat:@"%d",indexPath.row]])
{
    cell.frame = CGRectMake(640, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
    [arrObjectsDone addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
}
    [UIView beginAnimations:@"rotation" context:NULL];
    [UIView setAnimationDuration:1.0];
    cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
    [UIView commitAnimations];   
}

【讨论】:

  • 我认为你没有完全理解我!这个动画是由操作系统默认执行的,我想禁用它!
猜你喜欢
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
  • 2023-01-14
  • 1970-01-01
  • 1970-01-01
  • 2012-01-12
  • 2020-11-20
相关资源
最近更新 更多