如何在 macOS 中单击按钮时更改显示方向

发布于 2025-01-20 18:47:15 字数 694 浏览 2 评论 0原文

我想使用 Objective C 代码更改 macOS 中按钮单击事件的显示方向。

我想在我们从“系统偏好设置”打开显示时实现此功能,如果我们选择 90,则显示会旋转并且将以纵向模式显示。

图像显示“系统偏好设置”->显示设置:

“附加图像供参考”

我已尝试在按钮操作上执行以下代码,但它不起作用。我已经包含了#include

io_service_t service = CGDisplayIOServicePort(eDisplay); //IOKit Handle (get myDisplayID yourself)
IOOptionBits options = (0x00000400 | (kIOScaleRotate90)  << 16); //Some undocumented hex'ing
IOServiceRequestProbe(service, options); //Set rotation to display

我该如何解决这个问题?

I want to change the display orientation on button click event in mac OS using objective c code.

I want to implement this functionality when we open display from "System Preference" and if we select 90 then the display rotation happens and it will be displayed in portrait mode.

Image is displaying "System Preference" -> display settings:

Image is attached for reference

I have tried following code on button action but it is not working. I have included #include <IOKit/graphics/IOGraphicsLib.h>.

io_service_t service = CGDisplayIOServicePort(eDisplay); //IOKit Handle (get myDisplayID yourself)
IOOptionBits options = (0x00000400 | (kIOScaleRotate90)  << 16); //Some undocumented hex'ing
IOServiceRequestProbe(service, options); //Set rotation to display

How can I resolve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文