Over a million developers have joined DZone.

iOS: Computing Tilt Using Core Motion

DZone's Guide to

iOS: Computing Tilt Using Core Motion

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

Here’s an excellent tutorial on how to compute device tilt using Core Motion and quaternions:

Computing the iOS device tilt

“Quatta-whatons”, you ask? Why:

The beauty of Quaternions

If you don’t know what a quaternion is yet, please don’t be afraid by this strange word that seems right out of Star Trek.

Quaternions were first described by Hamilton in 1843 and applied to mechanics in three-dimensional space.

It eases the way we deal with the orientation of a body in a 3D space, and is better suited than the Euler angles that Apple is computing for us because of three reasons :

  • it’s easier to compose rotations or to extract values from it.
  • it avoids the gimbal lock problem.
  • and Apple provides a quaternion in the CMAttitude class instance.

And because we only want to compute the yaw we do not have to worry about the gimbal lock problem, since our goal is not to described the complete iPhone orientation in the 3D space but only the tilt…

Eyes glazing over yet? For a practical example of how to add some niftiness to your app with all this, check out

dulaccc / DPMeterView: “Gravity-aware gauge-style meter view with delightful animations.”


Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}