Matt,

Thanks for the help! I have a split view and I will replace the subview of the right half when a particular button is pressed in the menu. changeRightView is the method that handles it. The subview may be a tableview or a scrollview/textview and resizing the window or splitview will cause a blinking fade effect (default animation) in the right half of the splitview while it redraws the subview. From what I read, as long as the CALayer is there, it will have an animation of some kind and that's where the blinky fade effect is coming from. It seemed that setWantsLayer:NO was the right answer to get rid of the CALayer. Maybe it still is but my timing is bad?

Also, depending on what view is chosen to appear, I will have the push animation come from Right, Left or Top. I have a routine that will apply kCATransitionFromRight, kCATransitionFromLeft, or kCATransitionFromTop respectively. So I won't know what animation direction to come from till the user presses a button.

Here's what happens (is supposed to happen) in my program...
1. user presses button to change view
2. KVO gets a notification of button pressed and a if() statement decides which button was pressed.
3. setWantsLayer:YES
4. create CATransition and add the correct push animation direction per the button pressed
5. CATransition delegate set to self
6. Set those animations for the rightPlaceHolderView
7. replace the subview (hopefully cool animation happens here)
8. animationDidStop:finished: is called and setWantsLayer:NO

Thanks,
        Steve

On Oct 11, 2008, at 11:04 PM, Matt Long wrote:

Hey Steve,

Your call to setWantsLayer won't take effect until the next run loop. So here is what happens (I think).

- First call to changeRightView:
        - turns on layer backing for next run loop
        - adds the animation (transition) for next run loop
        - sets the delegate for the transition for next run loop
        - animation doesn't actually run
- Second call to changeRightView:
        - runs the animation added in previous call
        - turns on layer backing
        - adds the animation
- callback (animationDidStop) gets called since the animation ran and finished
        - callback turns off layer backing
- Third call to changeRightView:
        - turns on layer backing for next run loop
        - adds the animation (transition) for next run loop
        - sets the delegate for the transition for next run loop
- runs the animation added in previous loop, but won't actually run (or be visible) because layer backing was turned off.
- Fourth call same as the second:
        - runs the animation added in previous call
        - turns on layer backing
        - adds the animation
- callback (animationDidStop) gets called since the animation ran and finished
        - callback turns off layer backing

lather, rinse, repeat.

This will cause your transitions to do exactly what you describe-- every other iteration will look right.

Ok. So now how to solve your problem.... Not sure about that. If you can clarify what you are doing exactly, I might be able to offer a different solution. What do you mean by "I want the animation layer to go away". And I'm not sure how you're getting "blinky window resizing and other fun fade effects". Maybe show some more code?

Best Regards,

-Matt

p.s. Don't assume animationDidStop never gets called. Set a breakpoint or call NSLog() to be sure. ;-)


On Oct 10, 2008, at 6:53 PM, Steven Riggs wrote:

I'm enabling a core animation when I replace a subview and I want the animation layer to go away when the transition is finished so I don't have the blinky window resizing and other fun fade effects that I don't want. I have a problem with my code. The first time I changeRightView the CALayer appears and the view is transitioned from the right and the CALayer is gone. That's just what I wanted. The next time I changeRightView the CALayer appears but the view transitions using the default fade and then the CALayer stays. I assume animationDidStop:finished: never gets called because the CATransition never gets created or applied. So every other transition fails like this. good, bad, good, bad, good, bad... what did I miss?

See code below. Thanks for the help!

-Steve


- (void) changeRightView
{
        //enable CA layer
        [rightPlaceHolderView setWantsLayer:YES];
        
        //transition comes from the right
        CATransition *transition = [CATransition animation];
        [transition setType:kCATransitionPush];
        [transition setSubtype:kCATransitionFromRight];
        //set delegate for CAAnimation
        [transition setDelegate:self];

[rightPlaceHolderView setAnimations:[NSDictionary dictionaryWithObject:transition
                                                                                          
                                              forKey:@"subviews"]];
        //replace the view
[[rightPlaceHolderView animator] replaceSubview:currentRightView with:eventListView];
        currentRightView = eventListView;

        //size the view
        newBounds.origin.x = 0;
        newBounds.origin.y = 0;
newBounds.size.width = [[currentRightView superview] frame].size.width; newBounds.size.height = [[currentRightView superview] frame].size.height;
        [currentRightView setFrame:[[currentRightView superview] frame]];
        
        // make sure our added subview is placed and resizes correctly
        [currentRightView setFrameOrigin:NSMakePoint(0,0)];
[currentRightView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished: (BOOL)flag
{
//get rid of the animation layer so there's no fading on window resize
        [rightPlaceHolderView setWantsLayer:NO];
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to