IOS implements shake operations

  • 2021-01-02 22:00:19
  • OfStack

To achieve the function of shake 1, similar to WeChat shake 1

Method 1: The data of accelerometer is analyzed to determine whether the shake operation is carried out (relatively complex).

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

This paper introduces method 2:

Judge the steps of shake 1:

1) Start shaking detected


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

      // It can be done when detected 1 Some processing 

    }

2) Shake 1 shake is cancelled or interrupted


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

    }

3) Shaking ends


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

    // It can be done after it is finished 1 Some processing 

    }

All three methods inherit UIResponder.h from UIKit and can be used directly without the need for import class or Delegate inheritance

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: