small medium large xlarge

Generic-user-small
18 Aug 2010, 12:00
Ahsan Shafiq (1 post)

Hi

I am facing a problem in touch handling after the layer has animated.

I have a CALayer called a “wheel” and it contains sublayers on which I have to detect touches and move the wheel. here is my code for wheel animation

`
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
	
	// Get the touch point
	UITouch *touch = [touches anyObject]; 		
	CGPoint point = [touch locationInView:self.view];
	
	
	// Get the first wheel (the main wheel)
	CALayer *firstWheelLayer = [(DirectoryView*)self.view rootWheelLayer]; 
	
	//array of all layers in wheel
	NSArray *allLayersArray = [firstWheelLayer sublayers];
	
	
	//convert point to wheellayer
	point = [self.view.layer convertPoint:point toLayer:firstWheelLayer];
	
	for (CALayer* touchLayer in allLayersArray) {
		
		//CALayer *theLayer = [touchLayer hitTest:point];
		if([touchLayer hitTest:point]) {
 		        NSLog(@"HIT HIT");
			if ([touchLayer.name isEqualToString:@"3"]) {
				/* Animating the first (root) wheel, scaling down and 
					translating further down
				 **/
				NSLog(@"%@", touchLayer.name);
				//NSLog(@"x=%f, y=%f", point.x, point.y);
				//Scaling
				
				
				
				//CABasicAnimation* scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
				//scale.byValue = [NSNumber numberWithDouble:BIG_WHEEL_SCALE_DOWN_BY];
				//scale.cumulative = YES;
				
				//Trnaslation
				CABasicAnimation* translateX = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
				translateX.toValue = [NSNumber numberWithFloat:BIG_WHEEL_TRANSLATEX];
				translateX.cumulative = YES;
				CABasicAnimation* translateY = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
				translateY.toValue = [NSNumber numberWithFloat:BIG_WHEEL_TRANSLATEY];
				translateY.cumulative = YES;
				
				// Group animation
				CAAnimationGroup *theGroup = [CAAnimationGroup animation];
				theGroup.fillMode = kCAFillModeForwards;
				theGroup.removedOnCompletion = NO;
				theGroup.delegate = self;

				theGroup.duration = 1.0;
				theGroup.repeatCount = 0;
				theGroup.animations = [NSArray arrayWithObjects:translateX, translateY, nil]; // you can add more
				
				[firstWheelLayer addAnimation:theGroup forKey:@"ScaleAndRotate"];
`

So basically this is my code.
In this code "firstWheelLayer" layer contains some sublayers. now as animation is done, all sub layers are also scaled and translated w.r.t the super layer.
But now as I click the animated (moved) sublayer again it does not detect touch and if i click the previous position of that sublayer the above animation is repeated.


I have spent hours on this one.
Please help me out.
Regards
You must be logged in to comment