• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Non Linear CAAnimation of properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non Linear CAAnimation of properties


  • Subject: Re: Non Linear CAAnimation of properties
  • From: Bill Dudney <email@hidden>
  • Date: Mon, 19 Nov 2007 21:59:33 -0700

Hi Bertrand,

If I understand correctly you want a CAAnimationGroup to get your position and zPosition properties to animate at the same time (I've only done this on a layer backed view myself but it should work).

Here is the basic code that I'm using;

- (CAAnimation *)frameAnimation:(NSRect)aniFrame {
CAKeyframeAnimation *frameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
NSRect start = aniFrame;
NSRect end = NSInsetRect(aniFrame, -NSWidth(start) * 0.50, - NSHeight(start) * 0.50);
frameAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithRect:start],
[NSValue valueWithRect:end], nil];
return frameAnimation;
}


- (CABasicAnimation *)rotationAnimation {
CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"frameRotation"];
rotation.fromValue = [NSNumber numberWithFloat:0.0f];
rotation.toValue = [NSNumber numberWithFloat:45.0f];
return rotation;
}


- (CAAnimationGroup *)groupAnimation:(NSRect)frame {
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = [NSArray arrayWithObjects:
                        [self frameAnimation:frame],
                        [self rotationAnimation], nil];
    group.duration = 1.0f;
    group.autoreverses = YES;
    return group;
}

- (id)initWithFrame:(NSRect)rect {
...
NSDictionary *animations = [NSDictionary dictionaryWithObjectsAndKeys:
[self groupAnimation:[view frame]], @"frameRotation",
nil];
...
[view setAnimations:animations];
...
}


...
- (void)someEventMethod {
// since the animation auto reverses this works fine (if it did not auto revers we'd
//need to make sure that final rotation angle matched what is in the animation or we'd get jumpy movement)
[[movingView animator] setFrameRotation:[movingView frameRotation]];
}


I you should attach your keyframe animation with a CGPath to the position property and a basic animation to the zPosition. Then you can put both in a group then attach the group to the zPosition. Then when you set the zPosition for the layer it will animate both properties.

Some stuff to be aware of just in case you've not messed with groups before;
- the animations you put in the group have to be tied to the property they will be animating (i.e. use animationWithKeyPath: instead of animation)
- be aware that the final zPosition that you set should match the final position of the zPosition animation


I have been able to animate the size of a view and a layer with a CGPath, the x values mapped to the width and y values to the height. I could not find the code right now but it was the same kind of thing. All i had to do was tie the keyframe animation to the frameSize property.

HTH,

-bd-
http://bill.dudney.net/roller/objc

Hi List,

I'm trying to animate X and Z on a curve (rotating image a bit like
front row does). I can get the position correctly and have it linearly
animated from one position to the other, but i'd rather have it curve
a bit before since it would feel more natural than a straight line.

I thought the easiest way would be to use CAKeyframeAnimation and give
it a CGPath to follow. But it feels like that only works for animating
the position attribute or at least only for CGPoint attributes. Is
that the case ?

So I tried creating my own CGPoint and have it set the position and
zPosition. But my new attribute does not get animated. Not even the
default basic animation. What needs to be done for a property of a
subclass of CALayer to be animatable ?

Thanks.
Bertrand.
_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Non Linear CAAnimation of properties
      • From: "Bertrand Landry-Hetu" <email@hidden>
References: 
 >Non Linear CAAnimation of properties (From: "Bertrand Landry-Hetu" <email@hidden>)

  • Prev by Date: Re: physics engine?
  • Next by Date: Need iCal Parser
  • Previous by thread: Non Linear CAAnimation of properties
  • Next by thread: Re: Non Linear CAAnimation of properties
  • Index(es):
    • Date
    • Thread