objective-cxcodemacosnsimageview

Transition between NSImageViews in Objective-C


I am not very familiar with the Mac OS X APIs (coming from a long background of iPhone sdk) and I was wondering how I could add a transition when I switch nsimageviews. Does anyone have a short code snippet they can share about how to go about doing this?


Solution

  • This tutorial does pretty much the same thing, albeit with some extra things you probably don't need: http://www.cimgf.com/2008/03/03/core-animation-tutorial-wizard-dialog-with-transitions/

    In short, just call

    [[myWindow contentView] setWantsLayer:YES];
    [[[myWindow contentView] animator] replaceSubview:currentView with:newView];
    

    to do a crossfade animation of the two views. If you want to do a different type of animation, the fourth block of code in the tutorial should be of help.

    Be warned that using Core Animation layers ruins your font rendering, so you'll probably want to setWantsLayer:NO after the animation is complete also.