题外话:
 
权利的游戏开播了,引用一句话:
 
布兰:一个人如果还把,他还能勇敢么?
 
奈德:人在害怕时候的勇敢,才是真的勇敢。
 
 
回归正题:
 
说下关于 CMMotionManager 这个场景的应用吧,微信小视频不知道大家用过没,无论你横着录,还是竖着录,或者反着拿手机录视频,都会自动转成 正常录视频的样子(影像不会翻转),这种方式主要是通过陀螺仪的方式来实现。大家可以了解一下陀螺仪的声明方法,来仿照微信做一个腾讯小视频的录制功能。
 
陀螺仪代码如下:
 
 
#import <CoreMotion/CoreMotion.h>

CMMotionManager *motionManager = [[CMMotionManageralloc] init];
NSOperationQueue *queue = [[NSOperationQueuealloc] init]; //[NSOperationQueue currentQueue]
// 加速计
if (motionManager.accelerometerAvailable) {
    motionManager.accelerometerUpdateInterval = 1.f;
    motionManager.gyroUpdateInterval = 1.f;
    [motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData * _Nullable accelerometerData, NSError * _Nullable error) {
        if (error) {
            [motionManager stopAccelerometerUpdates];
            NSLog(@"error: %@", error);
        }
        else {
            NSLog(@"x--> %f\n y--> %f\n z--> %f\n",
                  accelerometerData.acceleration.x,
                  accelerometerData.acceleration.y,
                  accelerometerData.acceleration.z);
           
            [self hanldeAccelertionData:accelerometerData.acceleration];
        }
    }];
}
else {
    NSLog(@"This device has no accelerometer");
}

- (void)hanldeAccelertionData:(CMAcceleration)acceleration
{
    UIInterfaceOrientation orientationNew;
   
    if (acceleration.x >= 0.75) {
        orientationNew = UIInterfaceOrientationLandscapeLeft;
    }
    elseif (acceleration.x <= -0.75) {
        orientationNew = UIInterfaceOrientationLandscapeRight;
    }
    elseif (acceleration.y <= -0.75) {
        orientationNew = UIInterfaceOrientationPortrait;
    }
    elseif (acceleration.y >= 0.75) {
        orientationNew = UIInterfaceOrientationPortraitUpsideDown;
    }
    else {
        // Consider same as last time
        return;
    }
   
    IDSLOG(@"orientationNew: %ld", (long)orientationNew);
   
    if (orientationNew == orientationLast) {
        return;
    }
   
    orientationLast = orientationNew;
}

 
明天我会把 腾讯 微视频的代码分享给大家,其中录制方向使用陀螺仪来实现。
 
 
 
 
 
 

MotionManager 陀螺仪实现方式的更多相关文章

  1. iOS开发传感器相关

    手机里面内置了很多的传感器,例如:光传感器,湿度传感器,温度传感器,距离传感器等等 //开发传感器相关的东西必须使用真机 //在螺旋仪和加速计所有两种方式push和pull的方式,push的方式是时时 ...

  2. iOS中 陀螺仪/加速器 韩俊强的博客

    引进框架: #import <CoreMotion/CoreMotion.h> 定义属性初始化相关: #import "ViewController.h" #impor ...

  3. iOS学习新知识-加速计和陀螺仪

    一.CoreMotion框架介绍 我们知道有一些iOS的应用,会有一些特殊的要求,比如: 电子罗盘指南针之类的应用:让我们知道方向. 运动类型软件:让我们知道我们跑步多少公里. 社交软件中的摇一摇功能 ...

  4. iOS开发-CoreMotion框架(加速计和陀螺仪)

    CoreMotion是一个专门处理Motion的框架,其中包含了两个部分加速度计和陀螺仪,在iOS4之前加速度计是由UIAccelerometer类来负责采集数据,现在一般都是用CoreMotion来 ...

  5. iOS学习笔记34-加速计和陀螺仪

    一.CoreMotion框架介绍 我们知道有一些iOS的应用,会有一些特殊的要求,比如: 电子罗盘指南针之类的应用:让我们知道方向. 运动类型软件:让我们知道我们跑步多少公里. 社交软件中的摇一摇功能 ...

  6. [Xcode 实际操作]九、实用进阶-(9)陀螺仪设备的使用

    目录:[Swift]Xcode实际操作 本文将演示陀螺仪设备的使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit //导入需要用到的C ...

  7. iOS 重力感应 学习1 陀螺仪 水平仪 指南针

    小球可以随着重力感应 四处乱撞. 放大了坐标位移 就可以看见小球动了. 然后规定小球的路径 当滑到中间时候 弹出一张图片 作为提示. 我做了一个小demo 效果不错哦 CMMotionManager ...

  8. ios开发——实用技术篇Swift篇&加速计和陀螺仪

    加速计和陀螺仪 //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnim ...

  9. 简单VR照片 使用陀螺仪、姿态角(Roll、Pitch、Yaw )、四元数

        最近在做一个类似VR照片的demo,跟全景图片也很像,只是VR照片与全景720度显示,我只做了180度.但我发现他们实现的原理有一丝相似,希望可以给一些想入行AR.VR的朋友一些提示吧.   ...

随机推荐

  1. 【77.39%】【codeforces 734A】Anton and Danik

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. httpclient htmlunit下载单个文件

    httpclient public class Download { public static void main(String[] args) throws ClientProtocolExcep ...

  3. Atititjs javascript异常处理机制java异常转换.js exception process

    Atititjs javascript异常处理机制java异常的转换.js exception process 1. javascript异常处理机制 Throw str Not throw erro ...

  4. Android SDK location should not contain whitespace, as this cause problems with NDK tools

    解决方案一: The easiest solution is to move the SDK somewhere else, where there is no space or other whit ...

  5. Android Studio:Grade 全局参数定义

    Grade 全局参数定义 实际开发中设置公共的编译依赖参数等. 方法一: 在项目外层的build.gradle文件中定义,格式如下: 文件名:build.gradle ext { sourceComp ...

  6. 用 AJAX 读取xml 节点属性值

    <html> <head> <title>AjaxTest</title> <script> var xmlHttp; function c ...

  7. springboot 配置多数据源 good

    1.首先在创建应用对象时引入autoConfig package com; import org.springframework.boot.SpringApplication; import org. ...

  8. Android于popWindow写弹出菜单

    1.什么是popWindow? popWindow这是对话的方式!文字解说android的方式来使用对话框,这就是所谓的popWindow. 2.popWindow特征 Android的对话框有两种: ...

  9. 将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)

    原文:将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小) WPF的XAML文档(Main.xaml): <Window x:Class="SVG2Image.Ma ...

  10. modern-cpp-features

    C++17/14/11 Overview Many of these descriptions and examples come from various resources (see Acknow ...