这是问题所在。我在过去的几天里一直在搜索和尝试,并且没有运气就盯着那几行代码。任何帮助将不胜感激!
我正在尝试使用捏合手势进行缩放,并且它工作正常,直到我先旋转它,然后pich来缩放它。 cgrectmake()会忽略我传入的y和height值并且是疯狂的。这是代码:
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];
这是缩放前3个更改的日志。这些都是在时间紧密地结合在一起,当我几乎没有移动手指进行缩放时,所有这些都会发生。
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
您可以看到预期和实际y值和高度值完全无关,但x和宽度都很好。为了用图形描述,当我希望它在西北 - 东南方向上扩展时,它会向东北 - 西南方向移动并急剧缩小到一条线。
我已经尝试过cgrectmake,即使UILabel的原始值要进行缩放,也会出现相同的行为,没有任何区别。我也使用了调试器并确保我传入的那些值在cgrectmake之前和之后都没有改变......
我有什么遗失的东西吗?绝望需要帮助......