Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top