UIRotationGestureRecognizer - rotation around an anchor point

Here is my current gesture recognizer implementation:

- (IBAction)handleRotate:(UIRotationGestureRecognizer *)recognizer {

if([recognizer state] == UIGestureRecognizerStateEnded) {

    _lastRotation = 0.0;
    return;
}

CGFloat rotation = 0.0 - (_lastRotation - [recognizer rotation]);

CGAffineTransform currentTransform = self.container.transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

[self.container setTransform:newTransform];

_lastRotation = [recognizer rotation];

}

It works great. The problem is that self.container always revolves around the center. I would like it to rotate around the middle of two touches, so if you are zoomed in, you can just rotate around the area you are touching. How to do it?

+5
source share
2 answers

I'm not sure that you can set a point outside the bounds of a rotating object, but the property of your container level will allow you to specify a reference point from this transformation.

It takes values ​​from 0.0-1.0 at the top left to the bottom right.

#import <QuartzCore/QuartzCore.h>

[[container layer] setAnchorPoint:myCGPoint];
0
source

CGPoint,

recognizer.view.center = CGPoint(x,y);

( pangesturerecognizer , )

:)

1

. , () , multipal touch . (. )

multipal touch enabled in XIB

,

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"Began %@",touches);
    NSUInteger touchCount = 0;
    for(UITouch *tu in touches)
    {
        CGPoint pt = [tu locationInView:self.view];
        NSLog(@"pt %f, %f",pt.x,pt.y);
        touchCount ++;
    }
    NSLog(@"touchCount %d",touchCount);
}

NSLog. self.view , .

, , ,

p3.x = (p1.x + p2.x)/2; p3.y = (p1.y + p2.y)/2;

p1, p2 - , , p3 - , .

:)

0

All Articles