iOS晃动检测
2018-07-20 来源:open-open
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. }
标签: 代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:简单好用的PHP验证码类
下一篇:android的 Http工具类
最新资讯
热门推荐