首页 > 移动平台 > 详细

ios晃动检测

时间:2014-12-31 19:58:08      阅读:262      评论:0      收藏:0      [点我收藏+]

第一种

1、在AppDelegate.h中进行如下设置:

 

C代码  技术分享
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  2. {  
  3.     application.applicationSupportsShakeToEdit = YES;  
  4. }  

 

2、在你需要对晃动事件进行处理的ViewController中添加如下代码:

 

C代码  技术分享
  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.         NSLog(@"检测到晃动");  
  19.     } 

ios晃动检测

原文:http://www.cnblogs.com/iOS-mt/p/4196448.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!