zoukankan      html  css  js  c++  java
  • ios晃动检测

    第一种

    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.     } 
  • 相关阅读:
    Android 锁屏消息调研
    [GODOT]可复用移动组件(载具类)
    [GODOT]技能系统初探
    [GODOT]获取节点
    美丽的秋天
    生活
    day7.17
    html
    day 2015.6.08
    不会转载只能先留下网址了
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4196448.html
Copyright © 2011-2022 走看看