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
  • 相关阅读:
    iOS 9之适配ATS(转载)
    ios8 tableView设置滑动删除时 显示多个按钮
    PHP IDE phpstorm 快捷键
    ld: warning: directory not found for option 去掉警告的方法
    iOS 评论APP撰写评论
    集成IOS 环信SDK
    iOS Xcode7免证书真机调试
    iOS定时器
    配置安装CocoPods后进行 项目基本配置
    事务的概念
  • 原文地址:https://www.cnblogs.com/liuwj/p/6870037.html
Copyright © 2011-2022 走看看