【问题标题】:How and where can I change the animation of closing a NSPanel when I click the red close button?单击红色关闭按钮时,如何以及在何处更改关闭 NSPanel 的动画?
【发布时间】:2014-02-10 21:50:39
【问题描述】:

我在 NSWindowController 中展示了一个 NSPanel。当我按下 NSPanel 标题栏的红色小按钮时,我想用不同的动画改变它消失的方式。我怎么做?有没有类似 -(void)closeButtonPressed 的东西我可以改变。因为 NSWindow 的 -(void)close 没有像我想要的那样工作。当我展示它时,我会这样做:

[self.imagePanelController.previewPanel setFrame:NSRectFromCGRect(CGRectMake(self.window.frame.origin.x + self.window.frame.size.width/4 , self.window.frame.origin.y + self.bounds.size.height/4, self.ciImage.extent.size.width, self.ciImage.extent.size.height)) display:YES animate:YES];

我想在按下面板关闭按钮时再次设置一个新框架并为其设置动画。有什么想法吗?

【问题讨论】:

  • 没有将事物渲染成图层并为其设置动画,Windows 有一个animation behavior

标签: objective-c animated nspanel


【解决方案1】:

所以我自己想通了,它对我有用,我不知道这是否是最好的解决方案,但正是我需要的。所以我只是发布这个,如果有人正在寻找类似的东西。

我正在获取 NSPanel 的 closeButton 并对其执行操作以完全按照动画打开面板的方式关闭面板。

NSButton *closeButton = [self.imagePanelController.previewPanel standardWindowButton:NSWindowCloseButton];
    [closeButton setTarget:self];
    [closeButton setAction:@selector(closePanel)];

- (void)closePanel
{

    int calcX = self.window.frame.size.width - self.bounds.size.width;
    int x = self.window.frame.origin.x + calcX;
    int y = self.window.frame.origin.y;
    int width = self.bounds.size.width;
    int height = self.bounds.size.height;

    [self.imagePanelController.previewPanel setFrame:NSRectFromCGRect(CGRectMake(x, y, width, height)) display:YES animate:YES];
    [self.imagePanelController.previewPanel close];

}

【讨论】:

    猜你喜欢
    • 2015-08-16
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 2022-11-30
    • 2022-11-14
    相关资源
    最近更新 更多