Lets start out today’s tutorial on How to Rotate and Slide UIView in iOS Swift.
In this we will learn a little maths too, don’t freak out though after reading math….Just kidding. This is a update to our last tutorial on Custom UIView Shapes. We will start by placing a view on our storyboard and then create its outlet in our controller, change its color to blue and then we will start some coding stuff.
We will rotate the view 360° by applying the below code to our view.
In the first line we are rotating the view in z-axis. In next we are giving the angle M_PI is 180° and we are multiplying it by 2 for making it complete 360°. We call also give it duration and repeat count and same we will apply that animation to the view layer.
We can also create a method if we are using multiple view.
Hit cmd+R and run your project. Yo did it pal..nice (Y). the view centre is the same its not changing and the view it rotating full 360°.
Now Sliding a UIView, its not UIPangesture thought we will work or gesture in couple of days. We will set points of starting and final position and some mid and let the code made the view move.
Lets create a method to slide our view. Initially we will define Initial mid and final positions, then we create the path with that positions our view will move on that defined path. After that we create a CAKeyframeAnimation and apply it on the view.layer.