1

我的代码:

CGFloat scaleFactor = newSize.width / oldSize.width;
CGFloat newCenterX = center_.x * scaleFactor;
CGFloat newCenterY = center_.y * scaleFactor;

CGPoint newCenter = CGPointMake(newCenterX, newCenterY);
//newCenter.x = newCenterX;
//newCenter.y = newCenterY;

CGFloat newRaduis = raduis_ * scaleFactor;
newCenter.y += newSize.height - ceilf(scaleFactor) * oldSize.height;
NSLog(@"Convertion from %@ to %@", NSStringFromCGSize(oldSize), NSStringFromCGSize(newSize));
NSLog(@"old center = %@, old radius = %f", NSStringFromCGPoint(center_), raduis_);
NSLog(@"new center = %@, new radius = %f", NSStringFromCGPoint(newCenter), newRaduis);
NSLog(@"new center x = %f, new center y = %f", newCenterX, newCenterY);

并输出:

2012-09-14 14:18:35.027 TestApp[425:4b93] Convertion from {1080, 1920} to {320, 415}
2012-09-14 14:18:35.031 TestApp[425:4b93] old center = {246, 822}, old radius = 20.000000
2012-09-14 14:18:35.033 TestApp[425:4b93] new center = {73, -1261}, new radius = 5.925926
2012-09-14 14:18:35.035 TestApp[425:4b93] new center x = 73, new center y = 244

在输出中 - 新中心 = {73, -1261},新半径 = 5.925926。为什么中心y值为负?我做错了什么?

提前感谢您的帮助

4

1 回答 1

0

错误是因为你的线

newCenter.y += newSize.height - ceilf(scaleFactor) * oldSize.height;
  • scaleFactor大约0.2962ceilf(scaleFactor)等于1
  • newSize.heightis 415, oldSize.heightis 1920, so 415 - 1*1920is -1505, 并newCenter.y += -1505newCenter.yto 243.556=243.556 + (-1505)改变1261.444

所以这似乎是合法的 newCenter.y-1261在这条线之后。

于 2012-09-14T11:34:04.757 回答