Interface Builder Layer Transitions

  • I'm trying to use Core Animation to make a "push" transition for
    subviews inside a window with previous and next buttons.

    I tried setting the transition effects in IB for each view's "Order
    In" transition, as well as setting the containing view's "Subviews"
    transition, to no avail.

    [subviewArea addSubview:view] causes an immediate transition, while
    [[subviewArea animator] addSubview:view] causes a fade transition, not
    the transition I was expecting

    When I ask [[view layer] animationForKey:NSViewAnimationFadeInEffect]
    in gdb it returns nil. Not sure if this is related.

    Here is the test project I'm working on:
    http://beta.darknoon.com/andpoul/IBTransitionTest.zip

    I searched in the archive and didn't turn up anything. Any help would
    be greatly appreciated!

    —Andrew Pouliot / darknoon
  • On Jan 7, 2008, at 2:16 PM, Andrew Pouliot wrote:
    > I'm trying to use Core Animation to make a "push" transition for
    > subviews inside a window with previous and next buttons.
    >
    > I tried setting the transition effects in IB for each view's "Order
    > In" transition, as well as setting the containing view's "Subviews"
    > transition, to no avail.
    >
    > [subviewArea addSubview:view] causes an immediate transition, while
    > [[subviewArea animator] addSubview:view] causes a fade transition, not
    > the transition I was expecting
    >
    > When I ask [[view layer] animationForKey:NSViewAnimationFadeInEffect]
    > in gdb it returns nil. Not sure if this is related.
    >
    > Here is the test project I'm working on:
    > http://beta.darknoon.com/andpoul/IBTransitionTest.zip
    >
    > I searched in the archive and didn't turn up anything. Any help would
    > be greatly appreciated!
    >
    > —Andrew Pouliot / darknoon

    Hi Andrew,

    It's the contents of the "subviewArea" view's "animations" dictionary
    that matters, and there is a known problem with the IB inspector that
    prevents the requested transition type from being set properly in
    the .nib.  This is being worked on.  Meanwhile, if you set up the
    transition in code instead, you can make this work as desired.  Try
    changing your Controller class implementation to the following.
    You'll get a push transition that moves forward when the user clicks
    "Next", and back for "Prev".

    @implementation Controller

    - (void)makeCurrent:(NSView *)view direction:(NSString
    *)transitionDirection {
        if (current) {
            CATransition *transition = [CATransition animation];
            [transition setType:kCATransitionPush];
            [transition setSubtype:transitionDirection];
            [subviewArea setAnimations:[NSDictionary
    dictionaryWithObject:transition forKey:@"subviews"]];
            [[subviewArea animator] replaceSubview:current with:view];
        } else {
            [subviewArea addSubview:view];
        }
        current = view;
    }

    - (void)awakeFromNib {
        [self makeCurrent:view1 direction:kCATransitionFromLeft];
    }

    - (IBAction)next:(id)sender {
        NSView *view = (current == view2) ? view1 : view2;
        [self makeCurrent:view direction:kCATransitionFromRight];
    }

    - (IBAction)prev:(id)sender {
        NSView *view = (current == view2) ? view1 : view2;
        [self makeCurrent:view direction:kCATransitionFromLeft];
    }

    @end

    --
    Troy Stephens
    Cocoa Frameworks
    Apple, Inc.
previous month january 2008 next month
MTWTFSS
  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 31      
Go to today