简体   繁体   中英

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?

只需使用以下命令: [self setFrame:originalFrame display:YES animate:YES];

Guess your window is resized, but view you add to content view, don't. If you have only one view, then instead of:

[[self contentView] addSubview:view];

use:

[self setContentView:view];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM