【问题标题】:Animation of Auto Layout Constraint Not Happening inside NSTableCellViewNSTableCellView 内未发生自动布局约束的动画
【发布时间】:2018-07-13 19:55:55
【问题描述】:

我正在尝试使用 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 是我的NSTableCellView,progressWidthConstraint 是单元格内NSView 的宽度限制。

要让动画在NSTableCellView 中工作,我需要做些什么特别的事情吗?

【问题讨论】:

    标签: swift nstableview nstablecellview nsanimationcontext


    【解决方案1】:

    你可以试试

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

    【讨论】:

    • 同样的结果。没有动画。 ¯\_(ツ)_/¯
    • 成功了!所以我需要animator() 代理,嗯。有趣的。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 2019-06-05
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多