2009-07-19 14 views
0

iPhoneのロック解除メカニズムのようなスライダバータイプのUIコントロールを実装しました。アニメーションを含むUIImageViewを移動する

touchesEndedメソッドが呼び出されると、スライダが開始位置に戻ります。代わりに、私はそれを開始位置に戻すようにアニメートしたいと思います。

コードは次のようにする必要がありますが、動作しません。私はここで間違って何をしていますか?骨頭の質問に対して

CABasicAnimation *theAnimation; 
theAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"]; 
theAnimation.fromValue = [NSNumber numberWithFloat:BEGINX]; 
theAnimation.toValue = [NSNumber numberWithFloat: 0.0]; 
theAnimation.duration = 0.5; 
[self.unlock addAnimation: theAnimation]; 

申し訳ありません:

Self.unlockはUIImageViewです!

答えて

3

これは暗黙的なアニメーションを使用するともっと簡単に行うことができます。あなたは現在、このような何かをやっていると仮定:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
    myView.frame = startingFrame; 
    ... 
} 

は、あなたが(例えばそのフレームのような)ビューに加えた変更をアニメーション化する暗黙のアニメーターを使用することができます。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    ... 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    myView.frame = startingFrame; 
    [UIView commitAnimations]; 
    ... 
} 
+0

ねえ、おかげで...私はそれが間違っていると思う。私は次のコードを試して、私は "UIImageViewが応答しないかもしれない"という警告を数回出します:\t \t [self.unlock beginAnimations:nil context:nil]; \t \t [self.unlock setAnimationDuration:0.5]; \t \t self.unlock.frame = CGRectMake(0、0、75、37); \t \t [self.unlock commitAnimations]; –

+0

あなたのコードが書かれているとおりに正確であることはわかりません。魅力のように動作します。ありがとう! –

関連する問題