我想为外国 OS X 应用程序窗口的移动设置动画 [英] I want to animate the movement of a foreign OS X app's window

查看:23
本文介绍了我想为外国 OS X 应用程序窗口的移动设置动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我最近有两个显示器,想要一种将聚焦窗口移动到另一个屏幕的方法,反之亦然.我通过使用 Accessibility API 实现了这一点.(具体来说,我得到了一个 AXUIElementRef 来保存与焦点窗口关联的 AXUIElement,然后我设置了 NSAccessibilityPositionAttribute 值来移动窗口.

Background: I recently got two monitors and want a way to move the focused window to the other screen and vice versa. I've achieved this by using the Accessibility API. (Specifically, I get an AXUIElementRef that holds the AXUIElement associated with the focused window, then I set the NSAccessibilityPositionAttribute value to move the window.

我几乎完全按照我想要的方式工作,除了我想为窗户的运动设置动画.我想如果我能以某种方式得到 NSWindow,我就可以得到它的层并使用 CoreAnimation 来为窗口移动设置动画.

I have this working almost exactly the way I want it to, except I want to animate the movement of windows. I thought that if I could get the NSWindow somehow, I could get its layer and use CoreAnimation to animate the window movement.

不幸的是,我发现这是不可能的.(纠正我,但我错了——如果有办法做到这一点,那就太好了!)所以我向大家寻求帮助.如果我可以访问 AXUIElementRef,我应该如何为聚焦窗口的移动设置动画?

Unfortunately, I found out that this isn't possible. (Correct me I'm wrong though -- if there's a way to do it this way it'd be great!) So I'm asking you all for help. How should I go about animating the movement of the focused window, if I have access to the AXUIElementRef?

-R

--编辑

我能够通过创建一个 while 循环并每次将窗口的位置移动少量以制作成功的动画来制作粗略的动画.然而,结果相当不理想.您可以猜到,它需要大量不必要的处理能力,而且仍然非常不稳定.必须有更好的方法.

I was able to get a crude animation going by creating a while loop and moving the position of the window by a small amount each time to make a successful animation. However, the results are pretty sub-par. As you can guess, it takes a lot of unnecessary processing power, and is still very choppy. There must be a better way.

推荐答案

我能想到的最好方法是在窗口的 AXUIElement 信息值和从 CGWindow api 返回的信息之间执行一些hacky 属性比较.一旦您能够确定 CGWindow API 中的哪些窗口与 AXUIElementRefs 匹配,您就可以获取当前窗口内容的位图,用您自己的人造窗口的自定义动画绘制覆盖屏幕,然后在您放下覆盖层时设置真正的 AXUIElementRef到所需的动画结束位置.

The best possible way I can imagine would be to perform some hacky property comparison between the AXUIElement info values for the window and the info returned from the CGWindow api. Once you're able to ascertain what windows in the CGWindow API match AXUIElementRefs, you could grab bitmaps of the current window contents, overlay the screen with your own custom animation draw of the faux windows, then as you drop the overlay set the real AXUIElementRef's to the desired-end-animation positions.

哈基,不过.

这篇关于我想为外国 OS X 应用程序窗口的移动设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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