2009-11-26 28 views
0

我已經實現使用UIAccelerometer運動圖像。我已經使用下面的代碼。如何使用UIAccelerometer正確地移動圖像?

代碼:

float gravX = (acceleration. x * kFilteringFactor) + (gravX * (1 - kFilteringFactor)); 
float gravY = (acceleration. y * kFilteringFactor) + (gravY * (1 - kFilteringFactor)); 
float moveX = acceleration. x - gravX; 
float moveY = acceleration. y - gravY; 
CGPoint MoveCenter = [moveImage center]; 
float Movex = moveX * 30 + MoveCenter. x; 
float Movey = moveY * 30 + MoveCenter. y; 
moveImage.center = CGPointMake(Movex, Movey); 

在這種代碼有一個問題。如果我在頂部側移動設備隨後圖像在左側移動,如果設備是移動左側然後圖像被移動的上side.can你給我建議。

回答

0

也許是座標問題。 我不確定這是問題,但在Quartz中,(0,0)位於左下角,UIKit位於左上角。

試圖改變座標與frame.origin.xframe.origin.y而不是使用CGPoint。