nspopover

Force NSPopover resizing with animation


I have an NSPopover that I want to resize with animation. In my case, setContentSize works, but without animation (apple says that animation is not guaranteed).

I'm investigating the use of NSViewAnimation. With this approach, the popover does resize with animation, but this requires setting the popover (window) frame origin, not just its size.

Here lies the problem, I need to know the edge to which the popover is "attached" to its positionRect because this edge should not move during resizing.

To this end, have set a rather inelegant method that involves comparing the position of the popover to that of the view to which it is attached in screen space, but I'd like to know if there is a more elegant solution to reach my goal (suggestions in obj-c are preferred, I'm already old.)


Solution

  • The following code works:

    NSAnimationContext *currentContext = NSAnimationContext.currentContext;
        currentContext.allowsImplicitAnimation = YES;
        currentContext.duration = 0.2;
        currentContext.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
        [NSAnimationContext beginGrouping];
        popover.contentSize = contentSize;
        [NSAnimationContext endGrouping];