Parallax effect comes to IOS with the introduction of IOS 7. You can achieve this parallax effect inside your app by using the UIInterpolatingMotionEffect class. Let’s clarify parallax effect, the parallax effect makes your wallpaper to move left and right or up and down when user tilt his device. The parallax effect example is shown in the given below image.
Parallax effect IOS 7
To achieve the parallax effect in your app you can use the given below code which use UIInterpolatingMotionEffect class.
To check its functionality in more clear way lets create a project named ParallaxEffect.
Open ViewController.h and create an IBOutlet to UIImageView, we will add parallax effect to this UIImageView and let its name to be set as backGroundImageView.
Next we declare a method addParallaxEffect, in this method we will place our code which will give parallax effect to backGroundImageView.
Open Main.storyboard, drag an UIImageView object to view and connect IBOutlet to it.
Now open ViewController.m file, here we will define our method addParallaxEffect.
Here in above code we create an instance of UIInterpolatingMotionEffect and gave it type UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis, so when we add this it will give vertical effect to our view.
Now at this point we have both vertical and horizontal effects with us and we can apply them to our backGroundImageView. Now we have to group these effects into UIMotionEffectGroup object as view take UIMotionEffect object as parameter.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.