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?