2011-12-29 14 views
0

私は非常に簡単な問題がありますが、このバグの原因を見つけることができません。任意のアイデアを高く評価バグオブジェクトを移動して新しい座標を設定する際の修正

私はUIImageViewというオブジェクトを持ち、ポイントA(x1、y1)からポイントB(x2、y2)からポイントC(x2、y2)にフリック(移動)します。

AからBへ、CからDへ移動すると... アニメーションなしで動作します!

私は上のBにCからそれを移動....と...アニメーションで- >バグがあります!AからBまでの作品のみ、BからCまで、...などは他の場所に表示されます。

私は基本的にtouchesBegan方法、およびtouchesEndメソッドを実装し、

//NO ANIMATION ==> Works ! 

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"End of touch"); 

    UITouch *touch = [[event touchesForView:self.view] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 

    object.center = CGPointMake(location.x, location.y); 

} 

で新しい場所にオブジェクトを移動..

//ADDING ANIMATION ==> Bug ! 

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"End of touch"); 

    UITouch *touch = [[event touchesForView:self.view] anyObject]; 
    CGPoint location = [touch locationInView:touch.view]; 

    [self spinLayer:object.layer duration:1 direction:SPIN_CLOCK_WISE newFrame:location]; 
    tempFrame = location; // tempFrame is global. 
} 

とアニメーションの終わりに、私は

を行います
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { 

object.center = tempFrame; 

// I assign this because the object has to be updated to its new location to move it to points B, C, D and so forth... 

// The object is actually at the desired point. But it appears on the SCREEN at a different location although it `NSLogs` at the right point. 

} 

これはバグです:私はobject.center = tempFrame;を割り当てると

は、私は、オブジェクトが(X2、Y2)であることを期待しています。それは技術的には(x2、y2)です(私はNSlogの位置を見つけました)が、画面上の他の場所に表示されます。

ポイントCに移動すると、(x2、y2)が使用され、(x3、y3)に正しく移動しますが、画面上の別の場所に再び表示されます。

任意のアイデア??????

+1

は、我々は方法を見ることができ 'spinLayerにフラグメント

theAnimationX=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; theAnimationX.toValue=[NSNumber numberWithFloat:(newFrame.x-object.center.x)]; theAnimationY=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; theAnimationY.toValue=[NSNumber numberWithFloat:(newFrame.y-object.center.y)]; 

を変更:期間を:direction:newFrame: '? – joerick

+0

その単純なアニメーション... http://pastebin.com/P0ypj7RY – Legolas

+0

なぜ 'transform.translate.X/Y'の代わりに' position.x'と 'postion.y'キーをアニメーション化しないのですか?私は位置のアニメーションをチェックし、かなり細かく動作します –

答えて

1

アニメーションtransform.translation.xtransform.translation.yキーパスを使用する代わりに、position.xposition.yキーパスを使用することをおすすめします。 ので、

theAnimationX=[CABasicAnimation animationWithKeyPath:@"position.x"]; 
theAnimationX.toValue=[NSNumber numberWithFloat:newFrame.x)]; 
theAnimationY=[CABasicAnimation animationWithKeyPath:@"position.y"]; 
theAnimationY.toValue=[NSNumber numberWithFloat:(newFrame.y)]; 

ます。また、この場合にだけpositionキーパスを使用して(とtoValueとするCGPointを設定)

+0

すごい!あなたが私を助けることができる任意の方法http://stackoverflow.com/questions/8668731/moving-rotating-an-object-using-its-updated-position-and-tilt ????これはフォローアップですが、これとは別の質問です:) – Legolas

関連する問題