NSViewAnimation WTF

Seriously, what am I doing wrong here? Is the ability of NSViewAnimation to perform multiple animations at once just a cruel and twisted joke?

Download this little sample app (source code included; Tiger only etc) and run it. On my admittedly ageing PowerBook G4 1.67 (and on Lauren’s iBook), it’s jerky as hell – and it’s just animating four little blue square NSViews. It looks like some of the views even lag behind at times.

I really hope I’m just doing something incredibly stupid here.

Update: I created an NSAnimation subclass of my own (MGViewAnimation) to replace NSViewAnimation, which you should be able to drop straight into any existing code which uses NSViewAnimation. You can grab the source code from my Cocoa Source Code page, or you can read more about MGViewAnimation here.

11 comments

  1. FWIW, I see considerable “jerking” on my MacBook Pro. The animation, while fast, is everything but smooth.

  2. It’s much smoother if you use setAnimationBlockingMode:NSAnimationNonblockingThreaded or even setAnimationBlockingMode:NSAnimationNonblocking instead of setAnimationBlockingMode:NSAnimationBlocking
    … but it’s still a bit jerky on my PB G4 / 1.33GHz. Nowhere near as jerky as before though.

    Hope this helps,
    Ken

  3. Switching to setAnimationBlockingMode:NSAnimationNonblocking on a decently equpied Mac Pro makes it look pretty clean and consistent.

    The other two options clearly displayed the inequal movement you were talking about the other day.

  4. On my crappy MacBookPro 17 NSAnimationNonblocking seems to be the only thing that runs smooth. In all cases, that smoothness is pretty crappy as well. Something must be wrong somewhere.

  5. Yeah, nonblocking mode helps lots on my PB 12″ 768.

    Also, nonblocking threaded is actually more jerky than nonblocking normal on my computer.

    It’s funny, I was having this exact same problem just yesterday.

  6. You can get better performance out of NSAnimation if you create your own subclass and do the view animation manually. With a subclass, you only have a single NSAnimation thread running, but you can still update all four views at once.

    I made an example project that does something similar to yours, and demonstrates moving several views at once. You can get it here:

    http://tyandell.googlepages.com/Animation.zip

  7. All NSAnimation and NSViewAnimation classes were meant to be subclassed. You’re actually supposed to subclass them when you use them ;) I think…

  8. Ankur, NSAnimation is definitely meant to be subclassed, since it doesn’t do any actual animation itself or deal with any views or windows (it just saves a lot of the legwork involved in periodically getting notified of progress of a process, according to a specified animation curve).

    I wouldn’t at all say that NSViewAnimation is meant to be subclassed though. I can live with the idea that it’s just an example of what an NSAnimation subclass can do, but its purpose isn’t to be subclassed in the general case.

  9. Same twisted joke for me.

    I had done a project where I manually (i.e. using NSTimer) was fading and moving my windows. I decided to actually use NSViewAnimation instead – for properness and all.

    It’s incredibly bad at handling anything but the most trivial scenario it seems.

    Maybe NSAnimation with custom implementation of the fade and move methods would be better. It would still allow to ease in and out of the animations etc.

  10. thx for sharing you source code

    regards
    Allan

  11. [...] If it’s animating views you’re after, Matt Gemmell has got you covered. Initially having trouble with NSViewAnimation, someone neglected to tell him that it needs to be subclassed. However, Matt has recovered from his lapse in, uh, frustration and created a little sample animating views subclass. From his blog: It’s a partial rework of Todd’s NSAnimation Demo code, which subclasses NSAnimation directly and updates all the animated views’ frames itself in the same thread for better perceived performance. For basic “animate a bunch of views at once” uses, you should be able to just change NSViewAnimation to MGViewAnimation and go with it… But please read these caveats: This thing is barely tested at all [...]

Leave a comment