【问题标题】:how to write a toggle method to open/close a window?如何编写切换方法来打开/关闭窗口?
【发布时间】:2013-12-02 14:54:00
【问题描述】:

我的应用中有一个 NSPanel 窗口,我想使用工具栏上的按钮来切换打开和关闭。这似乎是一个相当基本的操作,而且确实是我在许多应用程序中看到的(例如 Inspector 视图)。但是,我正在努力寻找正确的方法来做到这一点。

我查看了 performClose: 和 makeKeyAndOrderFront: 方法,但我不知道如何使它们在我的方法中工作。基本上,我想要这样的东西

-(IBAction)togglePanel:(id)sender {  

if  (   ) //what do i put here to assess if _myPanel is already open?  

    // tell _myPanel to close  

else {  

        //tell _myPanel to open  

    }
  }

【问题讨论】:

    标签: cocoa osx-mavericks nswindowcontroller nspanel


    【解决方案1】:

    在这里回答我自己的问题。但是得到了我想要的:

    - (IBAction)togglePanel:(id)sender {
    if (_myPanel.isVisible == 0)
    
        [_myPanel makeKeyAndOrderFront:self];
    else {
        [_myPanel performClose:self];
          }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-03
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多