目的のCで画像を時計回りにするか反時計回りに回転するかを指定する簡単な方法はありますか?私は針でスピードメーターを持っています(自動車の価格を反映したデザイン) - それはニードルが画面の下側に回転し、反対側に回転している場合を除いて、うまくいきます。反時計回りに回すと数字が小さくなり、時計回りに回すと数字が上がります。私のコードセグメントは次のとおりです:CoreAnimation回転変換アニメーションの方向
// 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];
これは、元の点から新しい点までの角度が180度より大きくなるかどうかを知る方法がないことを除いて、私には有益です - 最初にどの角度を見つけるかが分からない限り針(UIView)は現在ですか?私は、古い価格を保存し、それを針の動きに取り入れる一連のコードを書く必要があると推測しています。 –