Search code examples
objective-ccocoacore-animation

How to Animate a custom NSWindow


I'm having some troubles animating a custom NSWindow.

Here's my init method:

- (CustomWindow *)initWithView:(NSView *)view
{
    if ((self = [super initWithContentRect:contentRect
                                 styleMask:NSBorderlessWindowMask 
                                   backing:NSBackingStoreBuffered 
                                     defer:NO])) {

        [[self contentView] addSubview:view];

        [self setBackgroundColor:[NSColor darkGrayColor]];
        [self setMovableByWindowBackground:YES];
        [self setExcludedFromWindowsMenu:YES];
        [self setOpaque:NO];
        [self setHasShadow:YES];
        [self setDelegate:self];
    }
    return self;
}

When I call [self setFrame:originalFrame display:NO animate:YES]; there is a delay that corresponds to the animation duration, but the animation itself doesn't occur.

I think this is because I'm using a borderless window?


Solution

  • Simply use this: [self setFrame:originalFrame display:YES animate:YES];