开发者

How do I properly move an image using UIAccelerometer?

开发者 https://www.devze.com 2022-12-13 01:59 出处:网络
i have implementing moving image using UIAccelerometer.I have used below code. code: float gravX = (acceleration. x * kFilteringFactor) + (gravX * (1 - kFilteringFactor));

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

精彩评论

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