Animating NSTabViewItem content change - how hard can it be?

  • I'm on the look for some tips how to animate NSTabViewItem change but
    so far haven't had any luck. I'm trying to have a such animation that
    when user clicks a new tab in a tabView, the old tab contents slides
    out of the view and at the same time the selected tabs content slide
    in. I can get the animation of old tabViewItem slide out, but I can't
    seem to be able to get the new tabViewItem to slide in at the same
    time, its like the view stays somewhere behind and unvisible. Any
    thoughts how this should be tackled? Below is NSTabView delegate that
    I'm using to catch the action of new tab selection.

    jokke h.

    - (void)tabView:(NSTabView *)tabView willSelectTabViewItem:
    (NSTabViewItem *)tabViewItem
        // slide out animation
    NSRect currentTabFrameStop;
    NSMutableDictionary* currentTabDict;
    NSView *currentTab = [[tabView selectedTabViewItem] view];
            // Create the attributes dictionary for the current tab view
            currentTabDict = [NSMutableDictionary dictionaryWithCapacity:3];

            // Specify which view to modify.
            [currentTabDict setObject:currentTab

      NSLog(@"taking out item index: %d and view: %@", [tabView
    indexOfTabViewItem:[tabView selectedTabViewItem]], currentTab);
      // Specify the starting position of the view.
            [currentTabDict setObject:[NSValue valueWithRect:[currentTab

            // Change the ending position of the view.
            currentTabFrameStop = [currentTab frame];
            currentTabFrameStop.origin.x += currentTabFrameStop.size.width;
            [currentTabDict setObject:[NSValue

    // slide in animation
    NSRect nextTabFrameStart;
    int indexOfSelectedTab = [tabView indexOfTabViewItem:tabViewItem];
    NSMutableDictionary* nextTabDict;
    NSView *selectedTabView = [[tabView
    tabViewItemAtIndex:indexOfSelectedTab] view];
            // Create the attributes dictionary for the next tab view item.
            nextTabDict = [NSMutableDictionary dictionaryWithCapacity:3];

            // Specify which view to modify.
            [nextTabDict setObject:selectedTabView

      NSLog(@"sliding in item index: %d and view: %@", indexOfSelectedTab,
            // Starting position of the view.
            nextTabFrameStart = [selectedTabView frame];
            nextTabFrameStart.origin.x -= nextTabFrameStart.size.width;
            [nextTabDict setObject:[NSValue valueWithRect:nextTabFrameStart]

            // Specify the ending position of the view.
            [nextTabDict setObject:[NSValue valueWithRect:[selectedTabView

        // Create the view animation object.
    NSViewAnimation *theAnim = [[NSViewAnimation alloc]
                    arrayWithObjects:currentTabDict, nextTabDict, nil]];

        // Set some additional attributes for the animation.
        [theAnim setDuration:1.4];
        [theAnim setAnimationCurve:NSAnimationEaseIn];
    [theAnim setAnimationBlockingMode:NSAnimationBlocking];
        [theAnim startAnimation];.
        [theAnim release];
previous month december 2007 next month
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today