I'm presenting a view in an NSPopover
, using code based on this sample code.
The view, and all of its sub-views, are layer-backed. There's a single NSImageView
, and several non-editable NSTextField
s. The text fields backgroundColor
s are set to [NSColor textBackgroundColor]
, and their textColor
s to [NSColor textColor]
. In this way, the text is black if one is using the normal theme, and white if one is using the "dark menu bar and Dock" option (which I'll refer to as "dark theme" from now on). This all works fine, and it looks a little somethin' like this:
The problem comes when I animate the NSImageView
up off the view. As it intersects with the NSTextField
s, the image appears to blend with the text fields in an unappealing manner. It happens in both light and dark themes, but it's more icky-looking (it's a technical term) in the dark theme. Dig it:
The code to animate it looks basically like this:
CABasicAnimation* positionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
positionAnimation.fromValue = [NSValue valueWithPoint:fromPoint];
positionAnimation.toValue = [NSValue valueWithPoint:toPoint];
positionAnimation.duration = imageAnimationDuration;
[self.imageView.layer addAnimation:positionAnimation forKey:@"position"];
self.imageView.layer.position = toPoint;
What have I tried? Oh, what haven't I tried?
First off, my own views don't have any kind of NSVisualEffectView
going on. But it seems that NSPopover
adds that on its own; you can clearly see my desktop bleeding through the popover in the animation above. That's fine; it's actually a nice effect. But, thinking that my NSImageView
was trying to be vibrant, I subclassed NSImageView
just to return NO
from allowsVibrancy
. No change in behavior.
Next, I subclassed NSView
to return NO
from allowsVibrancy
, and made the parent view of my view an instance of that. No change in behavior.
My NSTextField
s are set with drawsBackground
= NO
, so I changed them to YES
. No change in behavior. Then, leaving drawsBackground
= YES
, I set both text field's backgroundColor
s to [NSColor clearColor]
. Here's where it gets weird. This does make the weird drawing go away, but it changes the text color of one of the text fields (the smaller one) to black. Wut? See below.
I gave up on the background colors, and started messing with the text colors. I found that if I set the textColor
of the text fields to a discrete color (say, [NSColor blackColor]
or [NSColor whiteColor]
, then the weird drawing problem also goes away. It seems only to get weird when using colors which adapt with the theme such as [NSColor textColor]
. That's super lame, because the whole point of using something like [NSColor textColor]
is that it adapts to the theme. I could probably hack around and figure out what theme is active and set the colors manually, but I really don't want to go that route if I can help it.
I promise there's a question in here somewhere, and, mercifully, here it is:
How can I fix the animation issue shown above, while still using colors which properly adapt to the current theme?
Edit: The desired result is to have no blending between the image and the text. Something like this:
The image I used in the sample app here maybe isn't the best example to convey the sheer yuckiness of the animation I'm seeing in my actual app. The image in the sample is already mostly white, while in my actual app it's mostly black, and it truly looks horrible when blended with white text.