Why is [[NSWindow animator] setFrame ...] very laggy sometimes?
So, I have the following code to show mine 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 immediately after the user has clicked on the application status bar icon, so I use [[NSApp currentEvent] window].frame.origin.y/x
to get the location of the status bar icon.
This code works great, but sometimes it's very laggy and "jittery" and I don't know why. Any ideas on this and how to fix it?
source to share
The animator NSWindow
uses NSAnimation
, which means it quickly starts the timer to animate the window frame. At every frame of the animation, every view inside the window is redrawn. If you have large views with somewhat complex view hierarchies, the performance is pretty poor and there is no real way to work around it.
I would recommend JNWAnimatableWindow as a replacement for the NSWindow
default animator as it uses Core Animation CALayer
to perform animations and is therefore much smoother.
source to share