I have an image of a bottle, whenever us开发者_Go百科er 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.
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.
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.
精彩评论