开发者

How do I properly move an image using UIAccelerometer?

i have implementing moving image using UIAccelerometer.I have used below code.

code:

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);

In this code there is one problem.If i move device on top side then image is moving on left side,if device is move left side then image is moving top side.can you give m开发者_运维知识库e advice.


Maybe is a problem of the coordinates. I'm not sure this is the problem but in Quartz the (0,0) is on bottom left while on UIKit is on top left.

Try to change the coordinates with frame.origin.x and frame.origin.y instead of using CGPoint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜