Auto layout animation changes as content in the NSPopover database changes

I am trying to reproduce the behavior of iTunes 11 in navigation views inside a popover. I cannot find a way to make my animation happen at the same time as the popover changes contentSize.

I have a basic setup - this is a subclass of the MyPopoverNavigationView subroutine with two areas: old and new views, which I want the popover to move between. Popover contentViewControllerhas an instance of MyPopoverNavigationView in quality view. I'm doing it:

// Configure constraints how I want them to show the new popover view
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx) {
    [ctx setDuration:0.25];
    [ctx setAllowsImplicitAnimation:YES];
    [self layoutSubtreeIfNeeded];
} completionHandler:nil];

As far as I can tell from the Auto Layout WWDC 2012 videos, this is the recommended way to animate changes in view frames as a result of changes in constraints. It works, but the animation takes place in two stages:

  • Firstly, the popover contentSizewill change to accommodate the new view I’m moving on to (before this view becomes visible, so it partially obscures the existing content).
  • Secondly, the views are waiting, as I expect, so the system of restrictions that I set is fulfilled.

From setting some breakpoints, it looks like it -layoutSubtreeIfNeededultimately invokes a private method in popover called _fromConstraintsSetWindowFrame:that does popover size animation outside my animation group. The duration of my context is not respected, and my animations do not happen until the resize popover is complete.

How can I get my views for animation along with resizing popover?

+5
source share
2

, popover contentSize . GitHub. , :

// 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 contentSize so its animation happens simultaneously
containingPopover.contentSize = postTransitionView.frame.size;
+4

:

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)
})
0

All Articles