zoukankan      html  css  js  c++  java
  • 加速计

    // 1.创建加速计对象

        UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];

        // 2.设置代理

        accelerometer.delegate = self;

        // 3.设置采样时间

        accelerometer.updateInterval = 1.0/60;

        //实现代理方法

    #pragma mark - UIAccelerometerDelegate

    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration

    {

    NSLog(@"x = %.1f, y = %.1f z = %.1f", acceleration.x , acceleration.y , acceleration.z);

        // 获取加速度

        /*

         Vt = V0 + a * t (最终速度 = 初始速度 + 加速度 * 时间)

         Vt = V0 + g * t (加速度是恒定的9.8)

         Vt = V0 + g1 + g2 + g3 … (时间和加速度都是恒定的)

         Vt = V0 + a1 + a2 + a3 … (手机中时间是恒定的, 加速度不是恒定的)

         */

    }

    3、手机摇动事件

    - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event

    {

        // 判断摇晃事件类型

        if (motion == UIEventSubtypeMotionShake) {

            NSLog(@"摇一摇");

        }

    }

  • 相关阅读:
    php解析xml文件的方法
    while倒数阶乘的和
    菱形代码
    0929课堂随记
    0929作业
    0928练习作业
    HelloJava
    Java例题
    Hello World(本博客启程篇)
    vue 如何实现在函数中触发路由跳转
  • 原文地址:https://www.cnblogs.com/bluceZ/p/4629670.html
Copyright © 2011-2022 走看看