How to animate closing NSWindow to NSStatusItem? - macos

When you minimize an NSWindow you get a nice animation to the Dock. How to achieve a similar animation for "minimizing" to an NSStatusItem in the menu bar?
I have it set up where the NSStatusItem appears when you close the NSWindow but there is no animation.
I've tried animating the window frame but due to various layout contraints it has a minimum size that gets in the way.

To animate the whole NSWindow is not the right way and will result in a rubbish looking animation. I would suggest to capture a snapshot of the window and adding it to a transparent full screen window to animate layer of the image view. This way its fare more smooth. To get an idea how it could be implemented please take a look at this project on git.
Hope this will help.

Related

Strange behaviour of NSShadow for customized NSWindow

I subclass the NSWindow and use [self setHasShadow:YES] to set the shadow for window. But the shadow shows abnormally when:
Move the window a little out of the screen, then resize the window to a larger size, then when I drag back the whole window from outside the screen, I find that system does not draw shadow for those part covered by screen before.
the right part without shadow was covered by screen before
To get full shadow, I must resize the window again to let system redraw the shadow.
So is there a way to avoid this behaviour? Maybe it is more efficient to only the shadow for those parts in screen, but I hope it can redraw automatically when the whole window is in screen.

NSWindow resize indicator not visible

How do I show resize indicators for an NSWindow without Titlebar?
I created a new Xcode project(for Mac app) with storyboard. I just disabled the checkbox Title Bar in Appearance(It hides the Title bar of NSwindow).
The strange thing was, after disabling the TitleBar, NSWindow was not showing resize indicators while mouse was above the window edges. Although if I drag at edges it was resizing.
I guess this is a bug, because if the window can be resized by dragging the mouse over edges, it must show the resize indicators.
As it can be seen in the image, the resize indicators are seen after user drags the window, but many users would think that since there is no resize indicator, the window is not resizable.
I've fixed this issue by subclassing NSWindow and overriding canBecomeKeyWindow to return YES:
#import "MyWindow.h"
#implementation MyWindow
- (BOOL)canBecomeKeyWindow {
return YES;
}
#end
Not updating resize cursors in this case looks like Apple bug. Documentation states "The value of canBecomeKeyWindow property is YES if the window has a title bar or a resize bar, or NO otherwise.", so I expect that canBecomeKeyWindow will return YES for resizable window. But it doesn't.
UPD: Checked on 10.10.5. Hopefully, you will have same behaviour on 10.11.
I have not checked this, but you could set the resize indicators manually. I think I would add four NSTrackingAreas to the windows contentView subclass (one for each side of the window, only few pixels in height/width).
In the mouseEntered() method, create a new NSCursor object for the appropriate mouse position. Remember that the position could change, so use the mouseMoved() method as well.
On mouseExited() reset the cursor.
Again, I have not tried this, but it should work.
PS: Don't forget to file a radar on this ;)

Why does this textured NSWindow suddenly change its background gradient when resizing?

Can someone please tell me, why the background gradient of the textured NSWindow in this app suddenly changes, when you make the window a little bit smaller?
This is the minimal example I could find, that exhibits this behaviour. App & Source are available via Dropbox.
-- Updates:
If you put the slider lower,the gradient does not change when resizing the window:
Also, the change seems to happen when the distance between the slider and the window's right border gets smaller than the HIG says it should be.
It is really interesting question =)
I don't shure, but guess, this problem is connected to layers displaying.
If you still want to use textured window, you can put additional NSView object in the interface builder between NSView and NSSlider (NSWindow -> NSView -> NSView -> NSSlider). It fixes the bug.

NSWindow textured gradient fill weirdness

Hey, I've got a textured NSWindow, and I'm seeing some strange behaviour with the way it gets textured. If I have an IKImageBrowserView in the window, then there is a full light to dark gradient in both the title bar and the bottom bar of the window, but if I hide the IKImageBrowserView and show my NSBox, then the gradient starts light in the top, and ends dark in the bottom bar. I think screenshots may describe the problem more accurately.
Alternatively, is there a way of placing an NSTextField and an NSProgressIndicator overtop of an ikimagebrowserview? They aren't visible when placed above the ikimagebrowserview for some reason.
I experienced a similar issue with inconsistent NSWindow textured/metallic gradients.
My findings, and a solution which will work for the above issue may be found in the responses to the following post:
NSWindow textured background with NStextField

How to set transparency to HUD Window

I am using standard HUD window (Drag and drop from IB Library). But I don't see any control to set the transparency of this HUD window.
I also tried to customize NSPanel to create HUD window . But whatever the alpha value I set. It takes default alpha value. One more problem in this approach is I think I need to draw tittle bar.
Any solution or alternate solution is appreciated.
This page has an example that subclasses NSPanel and draws an HUD Window completely from scratch. The background color/alpha can easily be changed from HUDWindow.m.

Resources