Animation using UIGravityBehavior

iOS 7 now gives you some useful functions for amazing animations in the UIKit dynamics classes set. Here you will learn how to create falling objects in your iOS application using UIGravityBehavior.

Let’s start to learn step-by-step with demo application.

 

Step – 1 : First you need to create a new XCode Single View Application. This new application will have a ViewController.h and ViewController.m files.

Step – 2 : We need to edit ViewController.h file in order to start our demo application. We will add two properties in this file as below:

 

Step – 3 : Now we will put animation on an imageview, so place an imageview in the view controller in storyboard. And also place a button that we will use to start the animation.

Step – 4 : Now connect imageview with property “imageView” that we have created in ViewController.h file. And also create IBAction method that will run the animation when we click on start button.

 

Step – 5 : Now go to ViewController.m file and synthesize the properties as shown below :

 

 

Now implement the IBAction method as below :

That’s it about this demo. If you run the application and tap on “start animation” button, you will watch the UIGravityBehavior animation take place. The image of ball will fall down from top to bottom.

Let's Think together, Say Something !