IOS

IOS implements shake operations


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

    }
  1. Shake 1 shake is cancelled or interrupted
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event{

    }
  1. 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!