1) Для первого шага необходимо создать две переменные.
BOOL canPinch;
float oldScale;
2) Используйте ответ бригадира :) и добавьте его в свой метод инициализации
UIPinchGestureRecognizer* pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action: @selector (zoom:)];
[[[CCDirector sharedDirector] openGLView] addGestureRecognizer:pinchGesture];
3)
- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSArray* allTouches = [[event allTouches] allObjects];
UITouch* touch = [touches anyObject];
CGPoint location = [self convertTouchToNodeSpace:touch];;
CGRect particularSpriteRect = CGRectMake(spriteToZoom.position.x-[spriteToZoom boundingBox].size.width/2, spriteToZoom.position.y-[spriteToZoom boundingBox].size.height/2, [spriteToZoom boundingBox].size.width, [spriteToZoom boundingBox].size.height);
if(CGRectContainsPoint(particularSpriteRect, location))
{
if ([allTouches count] == 2)
{
canPinch = YES;
return;
}
else if ([allTouches count] == 1)
{
CGPoint touchLocation = [self convertTouchToNodeSpace:touch];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
CGPoint translation = ccpSub(touchLocation, oldTouchLocation);
[self panForTranslation:translation];
}
}
canPinch = NO;
}
- (void)panForTranslation:(CGPoint)translation
{
CGPoint newPos = ccpAdd(spriteToZoom.position, translation);
spriteToZoom.position = newPos;
}
- (void)zoom: (UIPinchGestureRecognizer*) gestureRecognizer
{
if (canPinch)
{
if (([gestureRecognizer state] == UIGestureRecognizerStateBegan) || ([gestureRecognizer state] == UIGestureRecognizerStateChanged))
{
spriteToZoom.scale = oldScale + [gestureRecognizer scale]-(oldScale != 0 ? 1 : 0);
}
if ([gestureRecognizer state] == UIGestureRecognizerStateEnded)
{
oldScale = spriteToZoom.scale;
}
}
}