Why is [[NSWindow animator] setFrame…] very laggy sometimes?

我是研究僧i 提交于 2019-12-22 10:53:49

问题


So, I have the following code to show my NSWindow:

[_window makeKeyAndOrderFront:self]; 

[NSAnimationContext beginGrouping];
[[_window animator] setAlphaValue:1.0];
[[_window animator] setFrame:NSMakeRect([[NSApp currentEvent] window].frame.origin.x - 102, [[NSApp currentEvent] window].frame.origin.y - 238, _window.frame.size.width, _window.frame.size.height) display:YES];
[NSAnimationContext endGrouping];

This code is called right after the user has clicked on the app's status bar icon, that's why I use the [[NSApp currentEvent] window].frame.origin.y/x to get the location of the status bar icon.
This code runs perfectly but, sometimes, it's very laggy and "jumpy" and I don't know why.
Any ideas about this and how to fix it?


回答1:


The NSWindow animator uses NSAnimation, which means that it rapidly fires a timer to animate the frame of the window. At each frame of the animation, every view inside the window is redrawn. If you have large views with somewhat complex view hierarchies, the performance is quite bad and there's no real way to work around it.

I would recommend JNWAnimatableWindow as a substitute for the default NSWindow animator, as it uses a Core Animation CALayer to perform animations on and therefore is much smoother.



来源:https://stackoverflow.com/questions/14542509/why-is-nswindow-animator-setframe-very-laggy-sometimes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!