2009-08-04 15 views
0

私は電話があります。 touchendで、彼はアニメーションで彼の位置に行きます。CGAffineTransformIdentityで時計回りに反時計回りに

角度が180°未満になるまで時計回りに戻ります。このコードでは問題ありません:

 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView beginAnimations:nil context:NULL]; 
[UIViewsetAnimationDuration:0.5]; 
wheel.transform = CGAffineTransformIdentity; 
[UIView commitAnimations]; 
}

しかし、それ以降は間違っていて、コンプリートターンのために回転し続けます。

私はこのようなアニメーションを作ってみました:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.2]; 
wheel.transform = CGAffineTransformRotate(wheel.transform, degreesToRadians(-130)); 
[UIView commitAnimations]; 
[self performSelector:@selector(animatewheelViewToCenter) withObject:nil afterDelay:0.3]; 
} 

- (void)animatewheelViewToCenter{ 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView beginAnimations:nil context:NULL]; 
[UIViewsetAnimationDuration:0.3]; 
wheel.transform = CGAffineTransformIdentity; 
[UIView commitAnimations]; 
}

それは動作しますが、アニメーションは流体ではありません。変更が表示されます。

答えて

1

touchesEnded(回転の点で)の状態がわかりませんし、degreesToRadians(-130)を選択して部分的に試してみて、残りの処理を行うことを期待しています。これは、あなたが期待している結果をうまく生み出す優れた解決策になるはずです。私はcadranが何であるか、なぜそれを回転させているのかは分からないので、ホイールを回転させるだけです。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.2]; 
    wheel.transform = CGAffineTransformMakeRotation(degreesToRadians(-130)); 
    // I would recommend that the degrees you rotate be half of whatever your rotation is. 
    // this would make the wheel rotate to the home position more evenly 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animatewheelViewToCenter:finished:context:)]; 
    [UIView commitAnimations]; 
} 

- (void)animatewheelViewToCenter:(NSString *)animationID finished:(NSNumber *)finished context:(id)context { 
    [UIView setAnimationBeginsFromCurrentState:YES]; // you might need to make this NO 
    [UIView beginAnimations:nil context:NULL]; 
    [UIViewsetAnimationDuration:0.2]; 
    wheel.transform = CGAffineTransformIdentity; 
    [UIView commitAnimations]; 
} 

EDIT:CGAffineTransformIdentityつもりので、戻って定期的に行くために最短経路を取るされているので実は、私はおそらく、どのようになるか半分よりもわずかに(例では-130度)回転になるだろうちょうど1/2の道を行くなら、それはあなたが望む正しい方向(時計回りまたは反時計回り)に行かないかもしれません。

+0

これは正しく、この目的のために実行している方法が間違っています。アニメーションは、最短パスをインデントに戻して回転させているため、問題が終了します。 – Daniel

+0

Thx "cadran"をすべて "wheel"に変更するコードを編集します。しかし、あなたのコードは、アニメーションに至るまでに時間がかかるので、私を助けます。 しかし、アニメーションはまだ流動的ではありません。 – Rufilix

関連する問題