我的代码:
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值是负数?我做错了什么?
提前感谢您的帮助
答案 0 :(得分:0)
错误是因为你的行
newCenter.y += newSize.height - ceilf(scaleFactor) * oldSize.height;
scaleFactor
约为0.2962
,因此ceilf(scaleFactor)
等于1
。newSize.height
为415
,oldSize.height
为1920
,因此415 - 1*1920
为-1505
,newCenter.y += -1505
为newCenter.y
}从243.556
更改为243.556 + (-1505)
= 1261.444
。因此,在这一行之后,newCenter.y似乎是合法的-1261
。