I'm working on a macOS App that uses auto-layout in a view hierarchy with layer backed views. The App uses an NSStackView
with several subviews that each feature a collapse/unfold button to resize the respective subview. Resizing of subviews is implemented by adding and removing layout constraints and an animation context is used to animate the size change. I implemented this as demonstrated on WWDC 2013, Session 213, starting at about minute 29:
@objc func disclosureToggeled(_ sender : Any) {
if isCollapsed {
self.addConstraint(collapseConstraint)
}
else {
self.removeConstraint(collapseConstraint)
}
NSAnimationContext.runAnimationGroup({ context in
context.allowsImplicitAnimation = true
self.window?.layoutIfNeeded()
})
}
The resize animation works as expected.
My problem: if I trigger a resize animation and a subview containing a focussed UI element is animated into a new position its focus ring immediately jumps from its starting to its final position while the UI element itself animates correctly.
Any idea what I am doing wrong?
答案 0 :(得分:0)
我认为,这与该视频中讨论的问题有关(跳窗调整大小)。视频中还讨论了解决方案
constraint.animator.constant
访问器或我发现,如果可以通过简单的常量更改来描述约束更改,则方法1更简单。