Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 功能建议:平滑的窗口 resize #158

Open
4 tasks done
rainzm opened this issue Aug 7, 2023 · 15 comments
Open
4 tasks done

🚀 功能建议:平滑的窗口 resize #158

rainzm opened this issue Aug 7, 2023 · 15 comments
Labels
enhancement New feature or request help wanted

Comments

@rainzm
Copy link
Contributor

rainzm commented Aug 7, 2023

请先确认以下事项

  • 已仔细阅读了 README
  • issues 页面搜索过(包括已关闭的 issue),未发现类似功能建议
  • Easydict 已升级到最新版本

功能描述

随着翻译结果的展出,窗口会resize,现在应该没有动画效果,比较突兀。希望能完善这块。

使用场景(可选)

No response

实现方案(可选)

No response

是否愿意提交 PR 实现该功能

  • 我愿意提交 PR!
@rainzm rainzm added the enhancement New feature or request label Aug 7, 2023
@tisfeng
Copy link
Owner

tisfeng commented Aug 7, 2023

你好,请问这个具体是指什么?可以录个视频看看吗

窗口会resize,现在应该没有动画效果,比较突兀

@rainzm
Copy link
Contributor Author

rainzm commented Aug 7, 2023

以下所有的实验都在 https://github.com/rainzm/Easydictwindow/smooth 分支下。

默认 快捷键划词 使用 mini 窗口: https://github.com/rainzm/Easydict/commit/7ca7f761d27f5904ba3822c15f785f1fdab47412

这其实就是默认的划词效果:

iShot_2023-08-07_21.07.47.mp4

可以,我感觉的问题是,窗口的变化不够平滑。

期望的效果:

iShot_2023-08-07_21.21.35.mp4

@rainzm
Copy link
Contributor Author

rainzm commented Aug 7, 2023

然后我更改EZUpdateTableViewRowHeightAnimationDuration1.0,便于观察,启用动画,见 https://github.com/rainzm/Easydict/commit/8c1424dfdd577ed46c2a47933f5e3a9cd8bed189

效果如下:

iShot_2023-08-07_21.47.28.mp4

loadingAnimation用卡顿,而且windows resize没有动画,和tableView明显区别。

然后我禁用loadingAnimation,见 https://github.com/rainzm/Easydict/commit/77c045a3f1b5abe0df283a31a7b7ed3c5c19486e

效果如下:

iShot_2023-08-07_21.51.57.mp4

@rainzm
Copy link
Contributor Author

rainzm commented Aug 7, 2023

然后,将NSWindow setFrame...animate:YES 改为 [NSWindow animator] setFrame,见 https://github.com/rainzm/Easydict/commit/c8e2af7dd75b4f0fc48c3f3e4a065aa0b3e132ea

效果如下:

iShot_2023-08-07_21.53.30.mp4

动画是有了,但是有些奇怪,搜了很久,找不到 这两种调用的区别

然后启用loadingAnimation,见 https://github.com/rainzm/Easydict/commit/9c74d73a92cbb3060c5baaec95c5414ecd632423

效果如下:

iShot_2023-08-07_21.57.11.mp4

@rainzm
Copy link
Contributor Author

rainzm commented Aug 7, 2023

@tisfeng 需要你的帮助 😂

@tisfeng
Copy link
Owner

tisfeng commented Aug 8, 2023

我晚上看下。

@tisfeng
Copy link
Owner

tisfeng commented Aug 8, 2023

了解了,目前更新动画确实有待优化。。

这是我第一次开发 macOS 应用,所以对 AppKit 的动画也不熟悉,还在慢慢摸索,前期为了折腾这个动画费了好多时间,最后勉强弄成现在这样。

我简单说下这块开发的思路和问题。

首先,更新高度动画分为两部份,一部分是 cell 自身的高度变化,其次是 window 的高度变化,而且理论上这二者的高度变化应该是同步的,我尝试使用 NSAnimationContext runAnimationGroup,但没有效果,所以目前两者的动画实际是分开进行的。

目前窗口更新使用的是 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;,这种更新方式的动画时间似乎是固定,0.2s,我尝试重写 NSWindow 的动画时间,但不知道为什么不行,总之,由于这个原因导致只能将 EZUpdateTableViewRowHeightAnimationDuration 的动画时间也设置为 0.2s,不然更新动画会不同步。你前面将时间改为 1.0s 出现的动画不协调问题就是这个原因。

@tisfeng
Copy link
Owner

tisfeng commented Aug 8, 2023

[NSWindow animator] setFrame 这种方式我也试过,但它的动画坐标系似乎不太一样,导致很难去调整适配,也就放弃了,当然也可能是我使用的方式不对 😢 macOS 开发的资料太少了,太难搞了。

@tisfeng
Copy link
Owner

tisfeng commented Aug 8, 2023

@rainzm 如果你对这个优化感兴趣,可以深入研究一下。

代码中需要优化的地方还有很多,有 TODO 标注。

/// TODO: we need to optimize the way of updating row height.
image

@tisfeng
Copy link
Owner

tisfeng commented Aug 8, 2023

@rainzm 你好,请问有兴趣进一步参与这个项目吗,改进文档,处理 issue,修复 bug,或是增加新的功能等等都可以 😃

@rainzm
Copy link
Contributor Author

rainzm commented Aug 8, 2023

@tisfeng 蛮有兴趣的 我也搞了半天这个动画 🤣

@rainzm
Copy link
Contributor Author

rainzm commented Aug 8, 2023

@tisfeng 关于 NSWindow setFrame with animateFlag[NSWindow animator] setFrame,我都打印了下窗口的变化过程:

image

结果是一样的,但是从最终的效果来看,感觉前者没有动画(等1s一到 直接过来了),或者是你说的时间不对,不过我也打印了 [NSWindow animationResizeTime] 确实是 1.0;然后后者是有动画,但是window的子视图好像重新绘制了(反正是动了),看上去,就像是从上往下加载了一下。确实感觉资料蛮少的。

@tisfeng
Copy link
Owner

tisfeng commented Nov 29, 2023

你好,请问这个调查有进展吗?

@rainzm
Copy link
Contributor Author

rainzm commented Nov 30, 2023

不好意思,没有进展,我对于objc以及macos的开发实在涉猎有限,这个问题可能需要一定基础, 所以我就暂时放弃了。

@tisfeng
Copy link
Owner

tisfeng commented Nov 30, 2023

好吧,这个问题确实有点难了。

那你有空可以处理一下其他的 issue 吗,有些问题停留很久了,我都来不及处理它们。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted
Projects
None yet
Development

No branches or pull requests

2 participants