Device motion detection in iOS

别说谁变了你拦得住时间么 提交于 2019-12-08 03:47:54

问题


I want to detect the device motion like Panorama i.e. motion from my left side to Right side.

I tried with the accelerometer but i can't able to do it.

I like to move one image in a straight line as the device move.

My code is as follow:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60];
    [[UIAccelerometer sharedAccelerometer]setDelegate:self];
}

pragma mark - Accelerometer Delegate

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:
(UIAcceleration *)acceleration{

    valueX = acceleration.x*100.0;
    valueY = acceleration.y*30.0;

    float newX = (float)(ball.center.x + valueX);

    CGPoint newCenter = CGPointMake(newX, 50);
    ball.center = newCenter;

}

How can I do this? Because there are many apps who uses this.

Please guide me.

Thanks..

来源:https://stackoverflow.com/questions/18779324/device-motion-detection-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!