Re: Add animation layer and then remove animation layer
Re: Add animation layer and then remove animation layer
- Subject: Re: Add animation layer and then remove animation layer
- From: Steven Riggs <email@hidden>
- Date: Mon, 13 Oct 2008 21:54:17 -0400
Wow, this is my problem described exactly. Is there a way to complete
the run loop so the animation will run during the original call to
changeRightView? I have a feeling I'm missing an important concept
here. Thanks for all the help.
- 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
- some magical thing happens
- animation does run
- callback (animationDidStop) gets called since the animation ran and
finished
- callback turns off layer backing
-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 (email@hidden)
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:
This email sent to email@hidden