如何使我的应用程序的触摸栏始终在macOS上可见? [英] How can I make my application's touch bar always visible on macOS?

查看:60
本文介绍了如何使我的应用程序的触摸栏始终在macOS上可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个MacOS菜单栏应用程序,该应用程序显示全屏覆盖.用户可以通过菜单栏中的滑块控制此覆盖图的不透明度.我希望将这些控件移至触摸栏,因为该应用程序用于屏幕记录,并且会记录主屏幕上的干扰.我的应用程序中的滑块应与默认情况下触摸栏上的亮度和音量滑块一样.

I am making a macOS menu bar application which displays a fullscreen overlay. The user is able to control the opacity of this overlay via a slider in the menu bar. I wish to move these controls to the touch bar, because the application is used for screen recordings, and distractions on the main screen would be recorded. The slider in my application should act just like the brightness and volume sliders that are on the touch bar by default.

我通过继承 NSApplication 并实现 makeTouchBar 添加了我的 NSTouchBar.该栏在首次启动该应用程序时出现.但是,在聚焦任何其他应用程序时,触摸栏会消失,并且似乎没有办法再次带走我的应用程序的触摸栏.我认为问题是我的应用程序是一个没有窗口的纯菜单栏应用程序.

I have added my NSTouchBar by subclassing NSApplication and implementing makeTouchBar. The bar appears when the application is first launched. However, the touch bar disappears when focussing any other application, and there seems to be no way to bring my application's touch bar again. The problem, I think, is that my application is a pure menu bar application with no windows.

以下是使我的应用程序的触摸栏可见的方法,从最优选到最不优选:

Here are the ways I could make my application's touch bar visible, from most preferable to least preferable:

  1. 在亮度和音量图标旁边,将我的应用程序的图标添加到控制条.即使在其他应用程序被聚焦时,这也可以让用户点击我的图标来调整不透明度.但是,奇怪的是,我是告诉我们没有公共API可以操纵控制条.

以某种方式为我的用户提供了一种将我的应用程序手动添加到控制条的方法.可以通过 System Preferences>来自定义控制条.键盘>Customize Control Strip ... (自定义控制条... ),显示了拖放到控制条中的各种内容.我想将我的申请注册为要包含在此处的项目.但是,我找不到任何方法.

Somehow give my user a way to manually add my application to the control strip. The control strip can be customized via System Preferences > Keyboard > Customize Control Strip ..., which shows a variety of things to drag-and-drop into the control strip. I would like to register my application as an item to include here. However, I cannot find any way to do this.

将我的应用程序注册为音乐应用程序.我机器上的Spotify以某种方式使用了控制条中的音乐"图标(与iTunes使用的图标相同).我不知道Spotify如何做到-其他人知道吗?显然,这将是一个hack,因为我的应用程序未播放音频,但总比没有好.

Register my application as a music application. Spotify on my machine somehow uses the "music" icon in the Control Strip (the same icon that iTunes uses). I don't know how Spotify does this - does anyone else know? Obviously, this would be a hack, as my application is not playing audio, but it's better than nothing.

以某种方式覆盖应用程序区域,以便我的应用程序的触摸栏始终可见,从而阻碍了所有其他应用程序对触摸栏的使用.这显然不是理想的,因为它不能与其他应用程序很好地配合.

Somehow override the App Region so that my application's touch bar is always visible, clobbering all other applications' use of the touch bar. This is obviously not ideal, since it doesn't play well with other applications.

这些解决方案有可能吗?还有其他可能的解决方案吗?如何使应用程序的触摸栏始终可通过触摸栏访问?

推荐答案

也许有一些骇人听闻的解决方案,但是根据官方文档,您不能这样做: https://developer.apple.com/reference/appkit/nstouchbar

Maybe there's some hacky solution, but according to official documentation you can't do it: https://developer.apple.com/reference/appkit/nstouchbar

在受支持的MacBook Pro机型上,键盘上方的Touch Bar,显示最前端应用程序中的NSTouchBar类的实例.

On supported MacBook Pro models, the Touch Bar, above the keyboard, shows instances of the NSTouch​Bar class from the front-most app.

这篇关于如何使我的应用程序的触摸栏始终在macOS上可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆