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");
        }
    }
  • 相关阅读:
    Linux常用命令-学习笔记
    Linux 输入输出重定向
    Linux 网卡配置参数
    JS Promise对象学习
    Linux用户身份与文件权限学习笔记
    4、点击事件
    3、自定义按压效果
    2、自定义背景形状
    1、文字大小,颜色
    5、跑马灯
  • 原文地址:https://www.cnblogs.com/ygm900/p/3089966.html
Copyright © 2011-2022 走看看