zoukankan      html  css  js  c++  java
  • [转]ios 判断左右摆动方法与 摇一摇

    
    首先在App's Delegate中设定applicationSupportsShakeToEdit属性:
    
        - (void)applicationDidFinishLaunching:(UIApplication *)application {
    
            application.applicationSupportsShakeToEdit = YES;
    
            [window addSubview:viewController.view];
            [window makeKeyAndVisible];
    }
    
    然后在你的View控制器中添加/重载canBecomeFirstResponder, viewDidAppear:以及viewWillDisappear:
    
    -(BOOL)canBecomeFirstResponder {
        return YES;
    }
    
    -(void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [self becomeFirstResponder];
    }
    
    - (void)viewWillDisappear:(BOOL)animated {
        [self resignFirstResponder];
        [super viewWillDisappear:animated];
    }
    
    
    最后在你的view控制器中添加motionEnded:
    
    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        if (motion == UIEventSubtypeMotionShake)
        {
            // your code
            NSLog(@"end animations");
        }
    }
    
    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    
        if (motion == UIEventSubtypeMotionShake)
        {
            // your code
            NSLog(@"begin animations");
        }
    }
  • 相关阅读:
    新的学习计划
    Python学习搬家啦
    安装数据库软件
    oracle11g RAC之grid安装
    PG源码编译安装
    vnc图形化远程centos7.6步骤
    postgresql 日期格式
    centos配置yum源
    pg创建多个实例
    PostgreSQL配置
  • 原文地址:https://www.cnblogs.com/ygm900/p/3089966.html
Copyright © 2011-2022 走看看