1

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!

Nick
  • 4,820
  • 18
  • 31
  • 47
  • Please ad some more info on when it stopped working. Did you upgrade Xcode, change iOS version in the target, etc? Can you go back to an older version where it still works, and then look for differences in your project? – koen May 20 '18 at 20:53
  • Thanks, @Koen. The problem is that it isn't a commonly used feature in the app, so it may have stopped working as a result of 11.3.1 or Xcode 9.3 or 9.3.1. I don't have any devices I can return to earlier versions. The deployment target is the original 11.2. – Nick May 20 '18 at 20:57
  • 1
    What does "has stopped working" mean? What happens when you make the gesture? – matt May 20 '18 at 20:58
  • Nothing. It doesn't re-size. It used to get smaller if you pinched your fingers together and bigger if you spread them apart. Usual stuff. – Nick May 20 '18 at 20:58
  • Is `resizeTargetRegistrationShape` being called when you make the gesture? It looks like you're saying it _is_ called, is that right? – matt May 20 '18 at 20:59
  • That's what I mean by 'selector'. Need all these characters to post a reply! – Nick May 20 '18 at 21:00
  • Did you try with an older simulator? Can you go back to an older version of your code where it still works? – koen May 20 '18 at 21:01
  • Can you post a working (i.e. nonworking) example project? i.e. just whittle the whole app down to this one label and this one issue. – matt May 20 '18 at 21:02
  • I tried, but my simulator seems only to offer 11.3. Is there a way of going back? – Nick May 20 '18 at 21:02
  • You can download older ones in Xcode -> Preferences -> Components – koen May 20 '18 at 21:03
  • @matt, thanks. It'll take a while, but I'll have a go. – Nick May 20 '18 at 21:03
  • Thanks, @Koen. I've set it downloading. – Nick May 20 '18 at 21:06
  • @matt, I've tried to create a minimal project and hit something interesting. It won't build because it gives "Assigning to 'readonly' return result of an Objective-C message not allowed" on the `transform` line. – Nick May 20 '18 at 21:15
  • Try something like `sender.view.transform = ...` or `[[sender view] setTransform:...]` instead. – ZachRabbit May 20 '18 at 21:23

1 Answers1

0

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])];
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks! It's strange that it only generates an error in a new project and definitely worked as was. I think I originally copied and pasted from another SO answer. – Nick May 20 '18 at 21:29
  • What was the last time you cleaned out your DerivedData? :) – matt May 20 '18 at 21:32
  • Probably haven't on this project. It's part of a VC that is still actively being changed elsewhere in the same source file, though. – Nick May 20 '18 at 21:34