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");
        }
    }
  • 相关阅读:
    程序员都必读
    ia-64 vs x86-64
    Linux内核学习
    开源liscense对比
    列存储
    大数据科普
    [USACO1.5]数字三角形
    [USACO08FEB]酒店Hotel
    数的划分
    CodeForce 18D
  • 原文地址:https://www.cnblogs.com/ygm900/p/3089966.html
Copyright © 2011-2022 走看看