Objective 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];