swift - 我在滚动时更改了 UITableViewCell 不透明度,但用户交互有一两秒的延迟。我怎样才能解决这个问题?

标签 swift uitableview opacity

尝试获取它以便将不透明度设置为 0,但是当显示单元格时,将其设置为 1。所以当我滚动浏览帖子时,我有一种淡入淡出的感觉。我得到了我想要的外观,但是当我滚动时,我有一两秒钟无法与 tableview 交互。

我也是 Swift 的新手,所以任何帮助都会很棒!!

这是我的代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    if let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? PostCell {

        cell.contentView.alpha = 0

        cell.updateUI(postData: posts[indexPath.row])

        return cell
    } else {
        return UITableViewCell()
    }

}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    UIView.animate(withDuration: 0.4) {
        cell.contentView.alpha = 1
    }
}

最佳答案

UIView.animate 默认会阻止用户交互。您可以尝试添加 .allowUserInteraction 选项。

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    UIView.animate(withDuration: 0.4, delay: 0, options: UIViewAnimationOptions.allowUserInteraction, animations: {
        cell.contentView.alpha = 1
    }, completion: nil)
}

关于swift - 我在滚动时更改了 UITableViewCell 不透明度,但用户交互有一两秒的延迟。我怎样才能解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51623814/

相关文章:

ios - 使用带有闭包的 TableViewCell 委托(delegate)函数时使用 [weak self] 的安全方法?

ios - 如何在 tableView 单元格上获取点击事件 UIbutton?

swift - 用 UITextView 填充 UITableViewCell(静态单元格)

javascript - 通过 jQuery 检查不透明度

css - 背景图像的不透明度和灰度过滤器。使它黑白透明

ios - 如何动态更改本地化 SwiftUI

ios - Alamofire 4 从类型 '(_) throws -> ()' 的抛出函数到非抛出函数类型 '(DataResponse<Any>) -> Void' 的无效转换

ios - 我如何通过解码获得 pdf 417 登机牌二维码详细信息?

ios - 上传符号运行脚本显示错误 "error: No API Key or Google Services file provided"

html - 如何使用 CSS 3 制作闪烁/闪烁的文本