zoukankan      html  css  js  c++  java
  • IOS 摇一摇的方法

    监控摇一摇的方法
    方法1:通过分析加速计数据来判断是否进行了摇一摇操作(比较复杂)
    方法2:iOS自带的Shake监控API(非常简单)

    判断摇一摇的步骤:实现3个摇一摇监听方法
    - (void)motionBegan:(UIEventSubtype)motion withEvent:

    (UIEvent *)event /** 检测到摇动 */


    - (void)motionCancelled:(UIEventSubtype)motion

    withEvent:(UIEvent *)event /** 摇动取消(被中断) */


    - (void)motionEnded:(UIEventSubtype)motion withEvent:

    (UIEvent *)event /** 摇动结束 */

    #import "HMViewController.h"
    #import <sys/socket.h>
    
    @interface HMViewController ()
    
    @end
    
    @implementation HMViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        Class c = NSClassFromString(@"UINavigationTransitionView");
        
        UIView *view =  [[c alloc] init];
        
        NSLog(@"%@", view);
    //    UINavigationController *nav = [[UINavigationController alloc] init];
    //    NSLog(@"%@", nav.view.subviews);
    }
    
    #pragma mark - 实现相应的响应者方法
    /** 开始摇一摇 */
    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        NSLog(@"motionBegan");
    }
    
    /** 摇一摇结束(需要在这里处理结束后的代码) */
    - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        // 不是摇一摇运动事件
        if (motion != UIEventSubtypeMotionShake) return;
        
        NSLog(@"motionEnded");
    }
    
    /** 摇一摇取消(被中断,比如突然来电) */
    - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
        NSLog(@"motionCancelled");
    }
    @end
  • 相关阅读:
    [原创]Acronis True Image使用手记
    毕业日志
    我的L6修好了
    三峡实习记之二
    初到华南理工印象
    三峡实习记之三
    SHOW毕业衫
    自己的第一次装机
    iOS Tools
    [转] A few things iOS developers ought to know about the ARM architecture
  • 原文地址:https://www.cnblogs.com/liuwj/p/6870037.html
Copyright © 2011-2022 走看看