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你給我建議。