UIPanGestureRecognizer - Translations and rotations not happening evenly with negatives vs positives

StackOverflow https://stackoverflow.com/questions/19395709

質問

Towards the top of the file I have this:

#define DEGREES_TO_RADIANS(x) (M_PI * x / 180.0)

In viewdidload I have this:

imageView.layer.anchorPoint = CGPointMake(0.5,0.5);

Then finally in the gesture recognizer I have this:

- (IBAction)handlePan:(UIPanGestureRecognizer *)sender {
    CGPoint translation = [sender translationInView:self.view];
    xPos += translation.x;
    if(xPos > 150) xPos = 150;
    if(xPos < -150) xPos = -150;
    float rotate = 0;
    if(xPos >= 50) {
        rotate = (xPos - 50) * 0.025;
    } else if(xPos <= -50) {
        rotate = (xPos + 50) * 0.025;
    }
    imageView.transform = CGAffineTransformTranslate(CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(rotate)), (xPos * 0.35), 0);
}

This appears to be applying the exact same effects to negatives (left) and positives (right).

With the UIImageView that is being rotated being placed in the center of the screen horizontally, and its anchor set to the center I would expect the maximum in both directions to be cut off equally by the edge of the screen. Instead the image goes much further to the right.

Left effect (negative): Left Rotation

Right effect (positive): Right Rotation

役に立ちましたか?

解決

It looks like autolayout changes the anchor point as the image view is rotated and the frame changes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top