Here is the problem. I have searched and tried in the past few days and staring at those few lines of code with no luck. Any help would be appreciated!
I am trying to zoom with a pinch gesture and it works fine until I rotate it first, then pich to zoom it. cgrectmake() would simply disregard my y and height values passed in and be crazy. Here is the code:
float width_delta = cos(angle) * self.selectedLabel.frame.size.width * (scale - 1);
float height_delta = cos(angle) * self.selectedLabel.frame.size.height * (scale - 1);
NSLog(@"delta width: %f delta height: %f", width_delta, height_delta);
NSLog(@"frame origin: %f %f", self.selectedLabel.frame.origin.x, self.selectedLabel.frame.origin.y);
float origin_x = self.selectedLabel.frame.origin.x - width_delta/2;
float origin_y = self.selectedLabel.frame.origin.y - height_delta/2;
float width = self.selectedLabel.frame.size.width + width_delta;
float height = self.selectedLabel.frame.size.height + height_delta;
NSLog(@"expected position: %f %f %f %f ",
origin_x,
origin_y,
width,
height);
self.selectedLabel.autoresizingMask = UIViewAutoresizingNone;
self.selectedLabel.frame = CGRectMake(
origin_x,
origin_y,
width,
height);
NSLog(@"real position: %f %f %f %f", self.selectedLabel.frame.origin.x, self.selectedLabel.frame.origin.y, self.selectedLabel.frame.size.width, self.selectedLabel.frame.size.height);
self.selectedLabel.font = [UIFont fontWithName:self.selectedLabel.font.fontName size:self.selectedLabel.font.pointSize * scale];
[pinchGesture setScale:1];
And here is the log for the first 3 changes on zoom. Those are all tightly together in time and all happen when I barely moved my finger to zoom.
2014-09-08 00:50:58.428 Crystals[5673:60b] scale: 1.000386 angle: -29.813133
2014-09-08 00:50:58.430 Crystals[5673:60b] delta width: -0.002168 delta height: -0.001471
2014-09-08 00:50:58.431 Crystals[5673:60b] frame origin: 46.324917 55.011127
2014-09-08 00:50:58.432 Crystals[5673:60b] expected position: 46.326000 55.011864 175.348007 118.976303
2014-09-08 00:50:58.433 Crystals[5673:60b] real position: 46.326000 8.780173 175.348007 211.439682
2014-09-08 00:50:58.434 Crystals[5673:60b]
2014-09-08 00:50:58.444 Crystals[5673:60b] scale: 0.999682 angle: -29.813133
2014-09-08 00:50:58.446 Crystals[5673:60b] delta width: 0.001786 delta height: 0.002153
2014-09-08 00:50:58.447 Crystals[5673:60b] frame origin: 46.326000 8.780173
2014-09-08 00:50:58.448 Crystals[5673:60b] expected position: 46.325108 8.779097 175.349792 211.441833
2014-09-08 00:50:58.449 Crystals[5673:60b] real position: 46.325104 -14.597655 175.349792 258.195343
2014-09-08 00:50:58.450 Crystals[5673:60b]
2014-09-08 00:50:58.451 Crystals[5673:60b] scale: 1.000000 angle: -29.813133
2014-09-08 00:50:58.452 Crystals[5673:60b] delta width: -0.000000 delta height: -0.000000
2014-09-08 00:50:58.453 Crystals[5673:60b] frame origin: 46.325104 -14.597655
2014-09-08 00:50:58.455 Crystals[5673:60b] expected position: 46.325104 -14.597655 175.349792 258.195343
2014-09-08 00:50:58.457 Crystals[5673:60b] real position: 46.325108 -26.417831 175.349777 281.835693
You can see that the expected and real y values and height values are completely irrelevant, but the x and width are good. To describe this graphically, when I want it to expand in the northwest-southeast direction, it would go northeast-southwest direction and shrink dramatically to a line.
I have tried cgrectmake even with the original value of the UILabel to be zoomed, and the same behavior occurs without any difference. I have also used the debugger and made sure that indeed those values I passed in are not changed before and after cgrectmake...
Is there something that I am missing? Desperation needs help...