iosobjective-cuipinchgesturerecognizer

Resizing UILabel using UIPinchGestureRecognizer has stopped working


This code used to work and cause a square UILabel, that has a border with corner radius set to half the length of the side (i.e. it looks like a circle), to re-size when pinched:

- (void)resizeTargetRegistrationShape:(UIPinchGestureRecognizer *)sender
{
    if ( [sender state] == UIGestureRecognizerStateBegan || [sender state] == UIGestureRecognizerStateChanged )
    {
        [[sender view] transform] = CGAffineTransformScale([[sender view] transform], [sender scale], [sender scale]);
        [sender setScale:1.0];
    }
}

The selector gets called with the correct UIPinchGestureRecognizer, the view is the correct label and scale value is reasonable. I've tried putting the transform on to the main thread, but no difference. The equivalent gesture to move it around in the view has continued to work. I've also tried putting a setNeedsDisplay and setNeedsLayout in as well, just to show how desperate I am!


Solution

  • This line was always wrong, and it's surprising that it ever appeared to work (indeed, I don't understand why it even compiled at any stage of this app's existence):

    [[sender view] transform] = 
        CGAffineTransformScale(
            [[sender view] transform], [sender scale], [sender scale]);
    


    What you mean is:

    [[sender view] setTransform: 
        CGAffineTransformScale(
            [[sender view] transform], [sender scale], [sender scale])];