Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CAnimation - setting CAAnimationGroup multiple times to the same object



I'm just starting out with Core Animation and Leopard dev.I'm having
some trouble with some trouble with  CAAnimationGroup.
In my application I need to animate a group of NSViews.  These NSViews
will animate a different way depending on what the user is doing.
Each NSView will need to call it's animation delegate so that it will
be informed when the animation has finished.
Basically I am able to set the NSView's animations to the
CAAnimationGroup the first time I perform an animation, but when I
need to animate the NSView with some different settings, when I apply
the CAAnimationGroup the second time, the animations (or group
animation) delegate doesn't get called ( animationDidStop:
(CAAnimation *) theAnimation finished: (BOOL)flag )

I set up the animations and group from my animationController object like:

	CABasicAnimation *duration = [CABasicAnimation animation];
	duration.duration = self.animationTime;

	CABasicAnimation *alphaAnimation = [CABasicAnimation
animationWithKeyPath: @"alphaValue"];
	alphaAnimation.fromValue = [NSNumber numberWithFloat: 0.0]; //<-- do a fade in
	alphaAnimation.toValue = [NSNumber numberWithFloat: 1.0];

	CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
	animationGroup.animations = [NSArray arrayWithObjects:
								 duration,
								 alphaAnimation, nil];

	animationGroup.duration = self.animationTime;
	animationGroup.delegate = newDelegate; //where newDelegate is
animationController which implements animationDidStop: (CAAnimation *)
theAnimation finished: (BOOL)flag

and then:

	NSDictionary *animDict = [NSDictionary dictionaryWithObjectsAndKeys:
animationGroup, @"frameOrigin", nil];
	
I have a group of subviews that need this animation

        for (myNSView *view in mySubViews)
        {
	     [view setAnimations: animDict];
	     [[view animator] setFrame: myNewFrameRect];
        }


This code work as expected, the animationDidStop gets called. But then
later on I need to take the same myNSView and do a different
animation:

	CABasicAnimation *duration = [CABasicAnimation animation];
	duration.duration = self.animationTime; //<--something different

	CABasicAnimation *alphaAnimation = [CABasicAnimation
animationWithKeyPath: @"alphaValue"];
	alphaAnimation.fromValue = [NSNumber numberWithFloat: 1.0]; //<-- do a fade out
	alphaAnimation.toValue = [NSNumber numberWithFloat: 0.0];

	CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
	animationGroup.animations = [NSArray arrayWithObjects:
								 duration,
								 alphaAnimation, nil];

	animationGroup.duration = self.animationTime; //<--something different
	animationGroup.delegate = newDelegate; //where newDelegate is
animationController which implements animationDidStop: (CAAnimation *)
theAnimation finished: (BOOL)flag

and then:

	NSDictionary *animDict = [NSDictionary dictionaryWithObjectsAndKeys:
animationGroup, @"frameOrigin", nil];
	
        for (myNSView *view in mySubViews)
        {
	     [view setAnimations: animDict];
	     [[view animator] setFrame: aDifferentNewFrameRect];
        }

It is when I try and add this new animation, the new animation
performs as expected but the animationDidStop function does not get
called.  The duration time is also not correct.  It defaults to the
default time setting.

I have tried many different ways of fixing this to no avail.
I've tried:
	[NSAnimationContext beginGrouping];
	[[NSAnimationContext currentContext] setDuration: self.animationTime];
	
        for (myNSView *view in mySubViews)
        {
	     [view setAnimations: animDict];
	     [[view animator] setFrame: aDifferentNewFrameRect];
        }

	[NSAnimationContext endGrouping];
and
	[view setAnimations: nil];
or
	[view.layer removeAnimationForKey: @"frameOrigin"];
even
	animationGroup.removedOnCompletion = YES;

Nothing seems to work. I'm sure that it is something basic.  Any clues
would be appreciated.

thanks

-- 
----
Bruce Johnson
email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.