Hello.
I want to rotate a CALayer by 90 degrees each time I click on it. but
the first attempt I tried i rotated the layer just once, and then I
click on it again and nothing happened.
this is the code.
-(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.contents != nil) {
NSLog(@"%@",[nLayer name]);
[nLayer setTransform:CATransform3DMakeRotation(90 * M_PI / 180, 0,
0, 1.0)];
}
}
then I tried the following, but of course because the position during
the animation is temporary once the animation its over it returns to
the original position
-(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;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
CALayer * nLayer = [anim valueForKey:@"rotatedLayer"];
//[nLayer
setPosition:CGPointMake(nLayer.frame.origin.x,nLayer.frame.origin.y)];
}
SO i dunno how to make the ayer stay in the final position after being
rotated. any ideas what can I do?
Thanks
Gustavo
_______________________________________________
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 arch...@mail-archive.com