2

I want to swap out one view with another by pushing the old view aside to slide in a new view (the kCATransitionPush type). To use CoreAnimation I need to work with CALayers with my views. The problem is that attaching a backing layer to my window content view through setWantsLayer distorts everything in the view.

I'm not sure if this has something to do with the fact that I'm using a subclass of NSWindow called MAAttachedWindow (http://mattgemmell.com/source), which is a HUD style transparent popup window of sorts that attaches to another element on the screen.

I can provide screenshots of this distortion if needed. I got the animation working through NSViewAnimation, but as many others have experienced, NSViewAnimation is terribly slow. I'd rather use CoreAnimation but this issue prevents me from using it.

Any insight is greatly appreciated

indragie
  • 18,002
  • 16
  • 95
  • 164
  • “I can provide screenshots of this distortion if needed.” Please do. – Peter Hosey Nov 10 '09 at 16:49
  • You also might try changing this to a regular window to test your theory. If the problem persists, then you'll probably want to describe a bit more about how you're approaching your solution. – Joshua Nozzi Nov 10 '09 at 18:41
  • Sometimes running your own animation piggy-backed on NSAnimation is the way to go; you probably don’t have to shift to CA. – Ben Stiglitz Nov 10 '09 at 23:04
  • Got some screenshots. Before attaching the layer: http://img21.imageshack.us/img21/43/screenshot20091110at412.png And after: http://img682.imageshack.us/img682/2558/screenshot20091110at424.png You can see that the text is noticeably smoother without the layer, and the vertical scroll bar gets a black background for some reason. I don't know why this is happening because I'm not doing anything fancy with the layer. And this doesnt happen on a normal window. NSViewAnimation works for this, but its slow. Any suggestions on how to speed it up? – indragie Nov 10 '09 at 23:36

3 Answers3

1

In addition to possibility of non-integral coordinates, to me the text appears to have been drawn into a non-opaque buffer. The LCD-aware Quartz text antialiasing doesn't work if it is drawn atop a non-opaque background color and then composited. Rather, your layer/view must fill the background with an opaque background color and then draw text above it.

One workaround for this that we've played with is to:

  • Draw your translucent background.
  • Draw your text with the background color, alpha=1, and add a stroke to the text of the same color, picking the stroke width to encompass the antialiasing area (beware resolution independence here).
  • Draw the text as normal, above this “landing pad”.

The issue with the scroller is possibly that the scroller is claiming -isOpaque but it isn't. Appropriate twiddling of the opaqueness and background color rendering should help.

tjw
  • 982
  • 5
  • 7
0

Given your saying the problem doesn't occur with normal windows, it's time to hawk-eye MAAttachedWindow. One of the first things I see when the window is created in this code is:

[self useOptimizedDrawing:YES];

What happens if you comment that line out? The next thing to look at is the drawing code. Also, the -_redisplay method disables/reenables screen updates, updating geometry and the background while this occurs. All of this would make me suspicious of its interaction with layer-backed views and animation.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Uncommenting that line didn't have much effect, but yeah its probably an issue with MAAttachedWindow. I think it was written before CoreAnimation was introduced. Rather than try and pick through the code to find whats wrong, I might try subclassing NSAnimation and rolling my own. Would that be a good solution? – indragie Nov 11 '09 at 00:11
  • Probably best posed as a new question. – Joshua Nozzi Nov 11 '09 at 01:13
0

Looking at how distortion increases makes me think that one or more of your views' bounds or frame are not integral.

Ben Stiglitz
  • 3,994
  • 27
  • 24
  • I'm not quite sure by what you mean by "integral" – indragie Nov 11 '09 at 18:05
  • Also, I tried what you suggested with NSAnimation. I created a subclass of it and my animation works, but its just as slow as NSViewAnimation – indragie Nov 11 '09 at 18:07
  • He means that the origin of your view's frame does not appear to lie on integer values for X and Y. If your view has an origin of (100.2, 200.5), you might run into the blurriness you're seeing. Correcting the origin to (100, 200) would remove that blurriness. – Brad Larson Nov 11 '09 at 18:55
  • Since the blurring is progressive across the image it’s probably the size of something that’s not integral, not necessarily the origin. – Ben Stiglitz Nov 12 '09 at 15:23