【问题标题】:How to show a view in this way on Cocoa Desktop?如何在 Cocoa Desktop 上以这种方式显示视图?
【发布时间】:2011-08-03 16:29:14
【问题描述】:

我正在做一个应用程序,我想知道如何显示这样的视图:

【问题讨论】:

    标签: macos cocoa nsview cocoa-sheet


    【解决方案1】:

    那将被称为一张纸。 This 指南将指导您完成操作。

    你基本上制作了一个NSWindow,你想将它用作工作表,然后,当你想显示它时,调用:

    [NSApp beginSheet: myCustomSheet modalForWindow: window modalDelegate: self didEndSelector: @selector(didEndSheet:returnCode:contextInfo:) contextInfo: nil];`
    

    myCustomSheet 显然是您的工作表,window 是您希望它出现的窗口。将self 设置为委托并实现didEndSheet:returnCode:contextInfo:

    - (void)didEndSheet:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
    {
        [sheet orderOut:self];
    }
    

    将工作表上的“关闭”按钮连接到关闭工作表的 IBAction

    - (IBAction)closeMyCustomSheet: (id)sender
    {
        [NSApp endSheet:myCustomSheet];
    }
    

    这些床单甚至不需要折叠!呵呵

    【讨论】:

    • 完美,但可以将工作表放置在比应用标题栏更下方的位置吗?
    • 不,您需要一个单独的窗口。
    【解决方案2】:

    这就是所谓的模态对话框。您可以通过拖入(或从代码中加载)单独的 NSPanel 或 NSWindow 来创建一个,并使用runModal... 方法之一显示它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多