zoukankan      html  css  js  c++  java
  • IOS 检测摇晃 几个问题

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://kyoworkios.blog.51cto.com/878347/1152692

     IOS3.0以后可以用如下

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

    }

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

    }

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

    }

    这三个方法检测手机摇晃事件。

    我说两个要注意的地方

    1.要实现摇晃的view或者viewController一定要添加

    -(BOOL)canBecomeFirstResponder{

        return YES;

    }

    注意不是-(BOOL)becomeFirstResponder;这个方法。

     

    2.在这个view的viewController中添加[view becomeFirstResponder]; 或者在viewController添加

    [self becomeFirstResponder];

    注意了以上这段代码必须添加在

    -(void)viewDidAppear:(BOOL)animated{

        [super viewDidAppear:animated];

        [self becomeFirstResponder];

    }

    这里

    (添加在其他地方就无效了)

    本人一开始添加在如下里

    -(void)viewWillAppear:(BOOL)animated{

        [super viewWillAppear:animated];

    }

    添加这里看似差不多,其实差远了完全接收不到摇晃事件。

    就这么多大家注意一下吧。

    本文出自 “做fashion的IT人” 博客,请务必保留此出处http://kyoworkios.blog.51cto.com/878347/1152692

  • 相关阅读:
    python中的unlink
    if
    python中if __name__ == '__main__'
    rename函数
    win2003的密钥
    url
    python中的os.stat
    python中的mysql
    防火墙
    网址
  • 原文地址:https://www.cnblogs.com/zsw-1993/p/4879631.html
Copyright © 2011-2022 走看看