Animating Auto Layout changes concurrently with NSPopover contentSize change

China☆狼群 提交于 2019-12-03 08:55:12

Turns out the trick is to explicitly set the popover's contentSize property outside of the animation and completion blocks. The relevant snippet from the sample GitHub project I put together to figure it out looks like:

// Configure constraints for post-navigation view layout
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx) {
    [ctx setDuration:0.25];
    [ctx setAllowsImplicitAnimation:YES];
    [self layoutSubtreeIfNeeded];
} completionHandler:^{
    // Tear down some leftover constraints from before the transition
}];

// Explicitly set popover's contentSize so its animation happens simultaneously
containingPopover.contentSize = postTransitionView.frame.size;

This works fine for me on Sierra:

let deltaHeight = 8 
let contentSize = popover.contentSize  
NSAnimationContext.runAnimationGroup({ (context) -> Void in
    context.allowsImplicitAnimation = true
    popover.contentSize = NSSize(width: contentSize.width, height: contentSize.height+deltaHeight)
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!