Re: What is the default time for a CALayer transform?
Re: What is the default time for a CALayer transform?
- Subject: Re: What is the default time for a CALayer transform?
- From: Dimitri Bouniol <email@hidden>
- Date: Tue, 16 Dec 2008 06:13:35 -0800
-(void)mouseDown:(NSEvent *)event
{
[event retain];
[mouseDownEvent release];
mouseDownEvent = event;
NSPoint p2 = [event locationInWindow];
NSPoint p3 = [self convertPoint:p2 fromView:nil];
CGPoint p = NSPointToCGPoint(p3);
CALayer * nLayer = [_gameboardLayer hitTest:p];
if (nLayer.name != nil) {
NSLog(@"%@",[nLayer name]);
CATransform3D transform = nLayer.transform;
transform = CATransform3DRotate(transform, M_PI_2, 0, 0, 1.0); //
rotate additional 90 degrees
CAAnimation* rotateAnimation = [CABasicAnimation
animationWithKeyPath:@"transform"];
rotateAnimation.fromValue = [NSValue
valueWithCATransform3D:nLayer.transform];
rotateAnimation.toValue = [NSValue valueWithCATransform3D:transform];
rotateAnimation.duration = 0.4;
[rotateAnimation setValue:nLayer forKey:@"rotatedLayer"];
[rotateAnimation setDelegate:self];
[CATransaction begin];
[CATransaction setValue:(id)bCFBooleanTrue
forKey:kCATransactionDisableActions];
nLayer.transform = transform; // set the layers "actual" value
without the user noticing
[CATransaction commit];
[nLayer addAnimation:rotateAnimation
forKey:@"RotationAnimation"]; // set this so it replaces the previous
rotation if you click before 0.4 sec
}
}
Hope that works :3 (apologies if I forgot a semicolon or something, i
wrote it directly in mail)
On Dec 16, 2008, at 5:54 AM, Gustavo Pizano wrote:
Dimitri Hi
using CAAnimation this is what I was doing:
-(void)mouseDown:(NSEvent *)event
{
[event retain];
[mouseDownEvent release];
mouseDownEvent = event;
NSPoint p2 = [event locationInWindow];
NSPoint p3 = [self convertPoint:p2 fromView:nil];
CGPoint p = NSPointToCGPoint(p3);
CALayer * nLayer = [_gameboardLayer hitTest:p];
if (nLayer.name != nil) {
NSLog(@"%@",[nLayer name]);
CAAnimation* rotateAnimation = [self animateForRotating];
[rotateAnimation setValue:nLayer forKey:@"rotatedLayer"];
[rotateAnimation setDelegate:self];
[nLayer addAnimation:rotateAnimation forKey:@"whatever"];
}
}
-(CAAnimation *)animateForRotating
{
float radians = 90 * M_PI / 180;
CATransform3D transform;
transform = CATransform3DMakeRotation(radians, 0, 0, 1.0);
CABasicAnimation* animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.toValue = [NSValue valueWithCATransform3D:transform];
animation.duration = 0.4;
animation.cumulative = NO;
return animation;
}
but hte animation once finished returned the layer to the initial
position something undesirable, I then set up a
animation.autoreverse = NO; but that didn't help either. I can see
here, somehow using CAAnimation its better, I can have more control
on how the rotation should look.
What do you think?
Thanks tons for your help
Gus
On 16.12.2008, at 14:37, Dimitri Bouniol wrote:
The Core Animation Programing Guide — http://developer.apple.com/documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimProps.html
#//apple_ref/doc/uid/TP40005942-SW2 — indicates 0.25 seconds are
used for an implicit animation.
As for using CABasicAnimation so you could use the delegate calls,
set the property (or key path) to the final value before adding the
animation to the layer, and you should get more appropriate results
as the animation ends. Additionally, you might need to wrap the
property call in a CATransaction to disable actions, but I don't
know if it's absolutely necessary.
--
定魅刀利
Dimitri Bouniol
email@hidden
http://www.appkainime.com/
_______________________________________________
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