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

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.

Related

NSTextView doesn’t work when placed near the top of an NSWindow

Context
I have a window with a fullSizeContentView and a transparent titlebar and hidden titlebar.
I don’t even want the titlebar, but I had to enable it to get rounded corners on the NSWindow.
Problem
An NSTextView, when placed near the top edge, doesn’t react to any clicks. It doesn‘t let me select any text, and doesn’t let me click links I added via NSAttributedString.
This issue disappears when I disable the titlebar altogether.
Any Help would be greatly appreciated. Thanks!
Big Context
I’m trying to implement little “in-app notifications” that show peripheral status updates. I considered using NSAlert but I don’t want to prevent the user from interacting with the rest of the interface while the notifications are showing, so I decided to implement it myself.
The notifications are little, non-movable windows without a titlebar. They are basically just grey rectangles with rounded corners and a shadow that draw inside the main application window and contain one or a few lines of text. The first line of text is almost entirely behind the invisible titlebar which is why I’m having issues.
The only thing I need the notifications to do besides display text is link to webpages that contain more info about a notification’s message.
I feel like I might be approaching this wrong. If you have any suggestions or ideas on how to solve the problem, I’m eager to hear them. Thanks!
I finally figured it out!
I nailed it down to the contentInsets of the NSScrollView. (which your are for some reason forced to have around your NSTextView when creating it in Interface Builder)
The contentInsets were automatically being set to account for the invisible titlebar, even though the docs say that NSScrollView - automaticallyAdjustsContentInsets (which is set to YES by default and which I assume was causing this) doesn't do automatic insets for transparent titlebars.
After programmatically setting the scrollView's contentInsets to 0, everything works great!
In Objective C, you can set your scrollView's contentInsets to 0 like this:
NSScrollView *scrollView = (NSScrollView *)self.textView.superview.superview;
scrollView.automaticallyAdjustsContentInsets = NO; // Doesn't remove insets // Probably calling this too late
scrollView.contentInsets = NSEdgeInsetsMake(0, 0, 0, 0);
Here's a working example.
Hope this helps!

How to animate closing NSWindow to NSStatusItem?

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.

When exactly does an NSWindow get rounded corners?

(I found several similar questions, but nothing quite the same. Some were older than the OS in question. Some were doing crazy things, like completely custom windows. Nobody I found has instructions for how to make a perfectly ordinary window work correctly.)
Starting in OS X Lion, standard windows have had rounded corners. Unfortunately, I'm having trouble replicating this in my application. When an NSView is pushed against the corner of an NSWindow, sometimes it stays clipped to the round NSWindow, and sometimes it escapes and makes a square corner.
I haven't been able to figure out a pattern yet.
Even NSViews that "draw their background" sometimes force square corners, so it's not that.
My custom NSViews make square corners (am I responsible for checking my position in the NSWindow, and clipping to that, if I'm near the edge?), but some standard Cocoa controls do this, too.
For example, make a new Cocoa project, put a (scrolling) NSTableView or NSTextView in the main NSWindow, and add layout constraints so it follows the edges of the window. The bottom corners are square! The Finder, in contrast, has (what looks like) an NSTableView, right up against the bottom corner of the window, and it's rounded.
How do I make an ordinary NSWindow, with the proper round corners on the bottom?
The flag to set, in order to get NSWindow to clip its contents to its actual window border (why the heck isn't this the default?) is NSView's wantsLayer.
In code: contentView!.wantsLayer = true, when the window is loaded.
Or in IB: select the root View of your Window, and then in "View Effects inspector", check the box next to it in "Core Animation Layer" (even if you're not using Core Animation).
Meta: the documentation for wantsLayer talks about a lot of complex things that don't seem at all related to window shape or clipping, and it's not even a property of NSWindow, while NSWindow has some flags that claim to be about window corner rounding but which don't work any more, so I'm not sure how anybody is supposed to discover this, except by spending 2 days on trial-and-error. I hope this answer helps somebody else!

NSSlider without background

When ever my NSSlider is displayed, it has a rounded rectangle background (see the linked image). I would like it to only have the bar and the knob drawn, not this background.
I have looked into subclassing NSSliderCell or NSSlider, but it seem that no matter what draw method I override this background will not go away. Is there anything I can do to get rid of this background, or are my only option to make my own control?
Thank you
Søren
Uncheck the Bordered option in Xcode or you can set it to NO in code.
If that doesn't work you've got it inside an NSBox or something

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

Resources