Ios screen rotation and shaking

Source: Internet
Author: User

The built-in accelerator is one of the coolest features of a smartphone. ios can use this small device to know how the user holds the mobile phone and whether the user has moved the mobile phone. ios uses the accelerator to process automatic rotation, in addition, many games use it as a control mechanism. It can also be used to detect shaking and other sudden movements. This feature has been further expanded since iPhone 4 and includes a built-in gyroscope, it can be used to determine the angle between the device direction and each coordinate axis.

First accelerator

By perceiving the total amount of inertial force in a specific direction, the accelerator can measure the acceleration and gravity. The accelerator in the ios device is a three-axis accelerator, this means that it can detect motion or gravity in three-dimensional space. Therefore, the accelerator not only indicates the way the phone is held (such as the automatic rotation function), but also indicates whether the phone is facing up or down if the phone is placed on the desk.

The accelerometer can measure g's gravity (g stands for gravity). Therefore, when the return value of the accelerometer is 1.0, 1g is perceived in a specific direction.

1. If you hold the iphone at rest without any movement, the force exerted by the gravity of the Earth is about 1 GB.

2. for vertical and vertical grip, the device detects and reports that the force applied on its Y axis is approximately 1 GB.

3. if the grip is held from a certain angle, the 1G force will be distributed to different axes. This depends on the grip mode, the 1G force is evenly divided into two axes. If it is detected that the acceleration value is much greater than 1g, it can be determined that it is a sudden movement. during normal use, the acceleration meter will not detect a value larger than 1g on any axis, if you shake, fall, or throw a device, the accelerator detects a great deal of force on one or more axes.

Shown in the Three-Axis Structure Used by the accelerator

 

Second Gyroscope

Gyroscope can be used to read the value that describes the rotation of a device around its axis.

If the difference between the sensor and the accelerator does not seem so obvious, consider the iphone that is flat on the desktop. If you rotate it while the phone is flat, the value of the accelerator will not change, this is because the force to move the phone (in this case, only the gravity is directly applied to the Z axis) has not changed.

 

Third, CoreMotion and Action Manager

In ios4 and later versions, the accelerator and gyroscope can only be accessed using the CoreMotion framework, which provides the CMMotionmanager class (of course there are other classes ), this class is used to describe how a user moves all values of a device.

The cmmotionmanager class is actually not an independent entity, but the application should regard it as independent. It should create only one CMMotionmanager class for each application and use the common alloc and init methods.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.