gpt4 book ai didi

ios - 在自动调整 TextView 大小时输入文本时 UITableView 闪烁/断断续续

转载 作者:IT王子 更新时间:2023-10-29 08:16:27 46 4
gpt4 key购买 nike

目前我有一个 UITableView,里面有一个可以调整大小的 UITextView。该单元格正在使用 beginUpdates/endUpdates 自动调整大小,但是当它这样做时,表格 View 会断断续续(参见下面的 gif)。

最终结果是一个 UITableViewCell,其中有一个 TextView ,它会根据其内容调整大小。以下是自定义 UITableViewCell 类中的代码,它会导致 UITableView 自行更新。

- (void)textViewDidChange:(UITextView *)textView {
// This is a category on UITableViewCell to get the [self superView] as the UITableView
UITableView *tableView = [self tableView];
if (tableView){
[tableView beginUpdates];
[tableView endUpdates];
}
}

以下是我已经尝试过的事情:

获取当前的 contentOffset 并在 endUpdates 之后重置它但是没有用在更新前禁用 UITableView 的滚动,然后在更新后启用我尝试总是从 - (BOOL)textViewShouldEndEditing:(UITextView *)textView 返回 NO我的 UITableView 单元格高度使用的是 UITableViewAutomaticDimension。欢迎任何其他想法或想法。

这是它的外观示例:

Table View Stutter

我不打算使用任何库,所以请不要对此提出任何建议。

谢谢

编辑:解决方案

在这里找到:I do not want animation in the begin updates, end updates block for uitableview?

归功于@JeffBowen 的伟大发现(尽管它是可行的并且允许我仍然实现支持 iOS 7 的 UITableViewDelegate 方法)。在执行更新之前关闭动画,然后在更新之后启用动画以防止 UITableView 卡顿。

[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];

如果您不需要使用 Delegate 方法并且只想为 iOS 8+ 提供一个不那么复杂的解决方案,那么请使用下面@Massmaker 的回答。

最佳答案

只需在调用 beginUpdates 之前禁用动画并在调用 endUpdates 之后重新启用它。

[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];

绝对是 hack,但目前有效。感谢我的 friend Beau,他向我指出了 this .

关于ios - 在自动调整 TextView 大小时输入文本时 UITableView 闪烁/断断续续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27460698/

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