How do I detect when someone shakes an iPhone?

后端 未结 16 2032
后悔当初
后悔当初 2020-11-22 06:41

I want to react when somebody shakes the iPhone. I don\'t particularly care how they shake it, just that it was waved vigorously about for a split second. Does anyone know h

16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 06:58

    Just use these three methods to do it

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

    for details you may check a complete example code over there

提交回复
热议问题