首页 文章

实时状态栏视图

提问于
浏览
1

我有一个状态栏应用程序,当我打开它时,它显示我的信息,但如果这些信息正在改变(这里的百分比),我不直接看到它 . 我必须重新打开它才能显示新的信息 .

在这里我打开应用程序一次它是90%:

Opening the app a fist time

然后我等了一段时间重新打开它,它已经100%了:

Opening the app a second time

有没有办法在状态栏应用程序中显示“实时”标签和内容?

1 回答

  • 1

    之前遇到过它:

    https://github.com/adamhartford/PopStatusItem

    很好,在弹出项目上似乎是线程友好的(已经使用异步线程测试过) . 编辑

    另外,因为用户需要实际状态栏图像/文本更新而不是弹出窗口...

    let sysStatusBar = NSStatusBar.systemStatusBar()
        dispatch_async(dispatch_main(){
            let dele = NSApp.delegate as? AppDelegate
            dele.statusBarValue = 100.0
                // from the delegate or a singleton method, have statusbarValue observed
                //      and update the App.delegate.statusBarItem.image accordingly.
                //      make sure it happens on the main thread... then the image / text
                //      will update...
        }
    

    您正在做的是更新您添加NSStatusBarItem并在那里更新图像的代理 . 在我的示例中,我更新了“statusBarValue”,但如果只是为该值添加绑定或观察者,则可以轻松更新图像 .

    ONCE AGAIN 确保在主线程上发生这种情况,或者UI只是忽略您的更新 . 所以来自后台线程等的更新......需要在主线程上调用 .

相关问题