gpt4 book ai didi

swift - NSTableCellView 内部未发生自动布局约束的动画

转载 作者:行者123 更新时间:2023-11-28 14:29:58 25 4
gpt4 key购买 nike

我正在尝试获取一个自动布局约束,以便在 NSTableCellView 中使用动画进行更新。约束可以正常更新,但动画不会发生这种情况。

下面的代码在tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int)中执行:

NSAnimationContext.runAnimationGroup({ (context) in
context.allowsImplicitAnimation = true
context.duration = 0.3
cell.progressWidthConstraint.constant = CGFloat(progress)
cell.layoutSubtreeIfNeeded()
})

cell 是我的 NSTableCellViewprogressWidthConstraint 是单元格内 NSView 的宽度约束。

我需要做些什么才能让动画在 NSTableCellView 中工作吗?

最佳答案

你能试试吗

NSAnimationContext.runAnimationGroup({ (context) in
context.allowsImplicitAnimation = true
cell.progressWidthConstraint.animator().constant = CGFloat(progress)
context.duration = 0.3
cell.layoutSubtreeIfNeeded()
})

关于swift - NSTableCellView 内部未发生自动布局约束的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51332037/

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