• 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
Rotating a CALayer more than once is not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Rotating a CALayer more than once is not working


  • Subject: Rotating a CALayer more than once is not working
  • From: Gustavo Pizano <email@hidden>
  • Date: Sat, 13 Dec 2008 15:50:05 +0100

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 (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: Rotating a CALayer more than once is not working
      • From: Steve Bird <email@hidden>
  • Prev by Date: Re: - [NSBitmapImageRep tiffRepresentation] malloc error
  • Next by Date: Re: Looking for info on creating Plugins/Modules
  • Previous by thread: Re: Main menu crash when migrating to Leopard
  • Next by thread: Re: Rotating a CALayer more than once is not working
  • Index(es):
    • Date
    • Thread