SoFunction
Updated on 2025-04-06

IOS implements a shake operation

To realize the function of shaking, it is similar to WeChat's shaking

Method 1: By analyzing the accelerometer data, we can determine whether the shake operation has been performed (more complicated)

Method 2: iOS comes with Shake monitoring API (very simple)

Method 2 of this article:

To determine the steps to shake:

1) The start of shaking is detected

 - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{

//After detection, some processing can be done
}

2) Shake is cancelled or interrupted

- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{

}

3) Shake ends

 - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{

//After the end, you can do some processing
}

The above three methods can be directly used without import class or Delegate.

Thank you for reading, I hope it can help you. Thank you for your support for this site!