使用 Xcode 以编程方式更改 Mac OS 上的显示旋转 [英] Programmatically Change Display Rotation on Mac OS using Xcode
问题描述
我正在尝试编写一个小的 Objective-C 命令行工具来调整给定显示的旋转.
I'm trying to write a small Objective-C command line tool that adjusts the rotation of a given display.
遗憾的是,我在 Apple 的文档中找不到任何关于如何更改旋转的参考(除了获取它).我认为必须使用 CGDisplayModeRef
来完成,但我不知道怎么做.任何帮助将不胜感激!
Sadly, I can not find any reference in Apple's documentation that tells how to change the rotation (aside from getting it). I think it has to be done with using CGDisplayModeRef
but I can't find out how. Any help would be appreciated!
推荐答案
摘自 https://github.com/CdLbB/fb-rotate - 似乎 IOKit
可以完成这项工作,尽管这种行为对我来说似乎有点奇怪.简而言之:
Extracted from https://github.com/CdLbB/fb-rotate - it seems IOKit
can do the job although the behavior seems a bit odd to me. In a nutshell:
io_service_t service = CGDisplayIOServicePort(myDisplayID); //IOKit Handle (get myDisplayID yourself)
IOOptionBits options = (0x00000400 | (kIOScaleRotate90) << 16) //Some undocumented hex'ing
IOServiceRequestProbe(service, options); //Set rotation to display
不要忘记链接IOKit
.
这篇关于使用 Xcode 以编程方式更改 Mac OS 上的显示旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!