有没有一种简单的方法来指定图像在物镜 C 中是顺时针还是逆时针旋转?我有一个带指针的速度表(一种反映汽车价格的设计)——它工作正常,除非指针向下旋转并从屏幕外移到另一侧更近。我希望它总是逆时针旋转到较低的数字,顺时针旋转到较高的数字。这是我的代码段:
// figure out the minimum and maximum prices shown on the
// speedometer
float min = [_a.text floatValue] * 1000;
float max = [_g.text floatValue] * 1000;
// set calibration between number labels to be small or large
int cal = SMALL_CALIBRATION;
if ([_stickerPriceSetting floatValue] >= TRIGGERPRICE)
cal = LARGE_CALIBRATION;
// set an animation duration of 1.5 seconds for the needle rotation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
// low prices (off speedometer)
if (price < (min - cal))
_needle.transform = CGAffineTransformMakeRotation(- M_PI/12);
// price too high (off speedometer)
else if (price > (max + cal))
_needle.transform = CGAffineTransformMakeRotation(M_PI * 13/12);
// need to have needle point to the price
else {
float delta = (max - min);
float price_point = price - min;
_needle.transform = CGAffineTransformMakeRotation(price_point/delta * M_PI);
}
[UIView commitAnimations];