1

I have an image of a bottle, whenever user shakes the device i want to move that image in that direction. like up, down, left or right.

For example: if user is shaking the device in left direction i want to move that image in left direction.

i can detect shake event using

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(event.subtype==UIEventSubtypeMotionShake)
{/*some code*/} }

but i dont know how to detect the direction.

i dont even if this is possible or not. please help me.

Virat Naithani
  • 783
  • 12
  • 31
  • 1
    What do you mean the direction of the shake? I wasn't aware that a shake has a direction. – PengOne Jun 03 '11 at 05:26
  • A shake doesn't necessarily have a direction. I often shake things by rotating my wrist quickly in random directions or wagging my would-be tail in a back and forth motion. – PengOne Jun 03 '11 at 05:29
  • For left and right, I posted my solution here : http://stackoverflow.com/a/29030985/1668837 – Jon - LBAB Mar 13 '15 at 11:28

2 Answers2

2

A shake is typically a back and forth movement. Use the accelerometer data to detect a sudden movement in one particular direction (e.g. left) or a tilt towards a different orientation.

PengOne
  • 48,188
  • 17
  • 130
  • 149
0

You can get user motion values using CMMotionManager class.Please refer the following link

http://developer.apple.com/library/ios/#documentation/CoreMotion/Reference/CMMotionManager_Class/Reference/Reference.html#//apple_ref/occ/cl/CMMotionManager

Filter your acceleration and gyro dat detect direction of motion.

itZme
  • 1,439
  • 9
  • 14