Everything every day here on Earth is based on gravity, and you don’t realize it until you don’t have it anymore.

Peggy Whitson

Chapter 2
Measuring Length with Gravitation

When it comes to physics phenomena, sometimes our intuition about what’s going on does not reflect reality. For example, two bodies with different masses experience the same acceleration when falling down in the gravitational field of the Earth. You might remember the experiment from school or from an online video where a feather and a rock fall in a vacuum. Without any surrounding air to create friction, they take the same time to hit the ground.

The same is true for swinging on a swing at the playground. No matter how heavy someone is, the period of the swing is always the same. It depends only on the length of the swing and the gravitational acceleration.

In this chapter we’ll use the iPhone’s built-in accelerometer to measure the period of a swing. With this value we’ll be able to calculate the length of the swing and display it in the user interface. In addition we will use the Core Graphics framework to draw the collected data on-screen. The user interface will be built using a storyboard and the Interface Builder in Xcode.

The result will look like a sophisticated measuring device as shown in the image, even though the code we need to achieve this isn’t complicated.

images/Sensors/swing_measurement_result.png

After working through this chapter, you’ll be able read the sensor data from an iPhone and present many kinds of data to your users.

You can use the sensor data in your own apps, for example, to add some playfulness to your user interface. This might prompt people to load your apps just because they’re fun to play with. The Core Graphics framework can do more than just draw data points onto the screen. By dipping your toe into Core Graphics, you’ll be taking the first step toward drawing custom user interfaces. This also can make your apps stand out from the millions of others in the App Store.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.199.243