【问题标题】:UITableViewCell not clickable when Blinking animation is implemented on itUITableViewCell 在其上实现闪烁动画时不可点击
【发布时间】:2021-10-11 09:20:31
【问题描述】:

在实现闪烁动画时,UITableViewCell 上没有执行任何操作,它开始闪烁很好,但不可点击或滑动。我尝试了一些解决方案,但无法修复它。代码如下。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
            cell.backgroundColor = UIColor.colorWithHexString(hexStr: "#FDFAEB")
            cell.blink()

        return cell
    }

动画扩展代码:

extension UIView {
    func blink() {
        self.alpha = 0.5;
        UIView.animate(withDuration: 0.7, //Time duration you want,
                       delay: 0.0,
                       options: [.curveEaseInOut, .autoreverse, .repeat],
                       animations: { [weak self] in self?.alpha = 1.0 },
                       completion: { [weak self] _ in self?.alpha = 0.8 })
    }
}

请告诉我,这是什么原因,我该如何解决?

【问题讨论】:

    标签: ios swift xcode animation uitableviewrowaction


    【解决方案1】:

    默认情况下,动画期间会禁用用户交互。您需要将.allowUserInteraction 选项添加到您的选项集中。

    (请注意,如果您正在为视图的位置设置动画,则用户将无法在视图移动时点击它。在幕后,一旦动画开始,视图就会跳转到它的目标位置。它似乎只在屏幕上移动。如果您想在视图在屏幕上移动时处理对它的点击,则要复杂得多。)

    【讨论】:

    • 谢谢,你救了我的命,我在动画选项中添加了 .allowUserInteraction,它起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    相关资源
    最近更新 更多