現在、時計の時針と分針を回転させようとしています。アプリ用に開発しているミニゲームの一つです。以下のこの関数は、時針と分針の両方の位置をランダムに設定します。現在、手を元の位置にリセットするために使用される回転を追跡しています。この問題は、最初または数回の回転後に発生し、分針がランダムな位置に表示されることがあります。これを修正または改善したり、精度を高めたりするにはどうすればよいですか? 私が持っている別の質問は、UIImageViews (左上? 中央?) の手の起源は何であるべきかということです。すべての提案は大歓迎です。
// function used to randomly move hands of clock and set answers
-(void)normal_move_hands
{
int hourHandLocation = arc4random() % 12; // 12 unique locations for hour hand
int miniuteHandLocation = arc4random() % 4; // 4 unique locations for minute hand
if(hourHandLocation ==0)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI / 6); // 1
rotationBackHour = (M_PI * 11 /6);
hourCorrectAnswer = [NSString stringWithFormat:@"1"];
}
if(hourHandLocation ==1)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI / 3); // 2
rotationBackHour = (M_PI * 10/6);
hourCorrectAnswer = [NSString stringWithFormat:@"2"];
}
if(hourHandLocation ==2)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI / 2); // 3
rotationBackHour = (M_PI * 3/2);
hourCorrectAnswer = [NSString stringWithFormat:@"3"];
}
if(hourHandLocation ==3)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI *2 /3); // 4
rotationBackHour = (M_PI * 4/3);
hourCorrectAnswer = [NSString stringWithFormat:@"4"];
}
if(hourHandLocation ==4)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 5 / 6 ); // 5
rotationBackHour = (M_PI * 7/6);
hourCorrectAnswer = [NSString stringWithFormat:@"5"];
}
if(hourHandLocation ==5)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI); // 6
rotationBackHour = (M_PI);
hourCorrectAnswer = [NSString stringWithFormat:@"6"];
}
if(hourHandLocation ==6)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 7 / 6); // 7
rotationBackHour = (M_PI * 5/6);
hourCorrectAnswer = [NSString stringWithFormat:@"7"];
}
if(hourHandLocation ==7)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 4 /3); // 8
rotationBackHour = (M_PI * 2/3);
hourCorrectAnswer = [NSString stringWithFormat:@"8"];
}
if(hourHandLocation ==8)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 3 / 2); // 9
rotationBackHour = (M_PI /2);
hourCorrectAnswer = [NSString stringWithFormat:@"9"];
}
if(hourHandLocation ==9)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 10 /6); // 10
rotationBackHour = (M_PI /3);
hourCorrectAnswer = [NSString stringWithFormat:@"10"];
}
if(hourHandLocation ==10)
{
hourHand.transform =CGAffineTransformMakeRotation(M_PI * 11 /6); // 11
rotationBackHour = (M_PI /6);
hourCorrectAnswer = [NSString stringWithFormat:@"11"];
}
if(hourHandLocation ==11) // 12
{
rotationBackHour = 0;
hourCorrectAnswer = [NSString stringWithFormat:@"12"];
}
if(miniuteHandLocation == 0) // 0 miniute
{
rotationBackMinute = 0;
minuteCorrectAnswer = [NSString stringWithFormat:@"0"];
}
if(miniuteHandLocation == 1) // 15 miniute
{
minuteHand.transform = CGAffineTransformMakeRotation(M_PI /2);
minuteCorrectAnswer = [NSString stringWithFormat:@"1"];
rotationBackMinute = (M_PI * 3/2);
}
if(miniuteHandLocation == 2) // 30 miniute
{
minuteHand.transform = CGAffineTransformMakeRotation(M_PI);
minuteCorrectAnswer = [NSString stringWithFormat:@"2"];
rotationBackMinute = (M_PI);
}
if(miniuteHandLocation == 3) // 45 miniute
{
minuteHand.transform = CGAffineTransformMakeRotation(M_PI * 3 /2);
minuteCorrectAnswer = [NSString stringWithFormat:@"3"];
rotationBackMinute = (M_PI /2);
}
}
これが私のリセット機能で、針を元の位置にリセットするために使用されます。
-(void)reset_hands
{
hourHand.transform = CGAffineTransformMakeRotation(rotationBackHour);
minuteHand.transform = CGAffineTransformMakeRotation(rotationBackMinute);
}