Skip to content

iTofu/ShakeDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShakeDemo

摇一摇示例代码。

image

前言 Foreword

iPhone上的摇一摇实现很简单。具体参考下面的代码或者下载Demo试一下。

代码 Code

  • 在需要响应摇一摇的controller中,设置canBecomeFirstResponder
     - (BOOL)canBecomeFirstResponder {
     	
     	return YES;
     }
  • 直接实现下面的代理方法即可:
     #pragma mark - 摇动
     
     /**
      *  摇动开始
      */
     - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
         
         if (motion == UIEventSubtypeMotionShake) {
             
             NSLog(@"开始摇了");
         }
     }
     
     /**
      *  摇动结束
      */
     - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
         
         NSLog(@"摇动结束");
     }
     
     /**
      *  摇动取消
      */
     - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
         
         NSLog(@"摇动取消");
     }
  • 模拟器调试技巧:

image

联系 Support

授权 License

本项目采用 MIT license 开源,你可以利用采用该协议的代码做任何事情,只需要继续继承 MIT 协议即可。

Releases

No releases published

Packages

No packages published