清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1、在AppDelegate.h中进行如下设置: 1. -(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2. { 3. application.applicationSupportsShakeToEdit = YES; 4. } 2、在你需要对晃动事件进行处理的ViewController中添加如下代码: 1. -(BOOL)canBecomeFirstResponder{ 2. return YES; 3. } 4. 5. -(void)viewDidAppear:(BOOL)animated{ 6. [super viewDidAppear:animated]; 7. [self becomeFirstResponder]; 8. } 9. 10. - (void)viewWillDisappear:(BOOL)animated{ 11. [self resignFirstResponder]; 12. [super viewWillDisappear:animated]; 13. } 14. 15. -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 16. { 17. if (motion == UIEventSubtypeMotionShake) { 18. 19. 在这里写晃动时 触动的事件 20. } 21. }