Hi, Alex here from rebeloper.com and welcome back to these extensions series in Swift
and today we are going to take a look at some awesome navigation extensions.
So without further ado let's jump right into it.
Okay, let me just show you what we
are going to build out today by running this testing extensions fun and again
go ahead and take a look at the link and down in the description to download the
starter project. Now here we have a navigation and if we push from right we
go back and that is the basic push pop navigation style. We are sliding the new
view controller from the right to the left but what if we wanted to push from
the left and we wanted to pop from the right. So let's just click on that and
pop to left and there we go and it is simple as that. Maybe you want to
implement it maybe you don't but if you do you can learn today. So let's just
stop this and take a look at our extensions fun project and let me just
set the example type to be navigation and again go ahead and take a look at
the first video of this series on how to download and how to make all of what
this starter project is or if you just want to deep dive into it just go ahead
and launch the starter project and take a look at the navigation view controller
and let me just guide you through what we have here. Well first of all we
have a white background we set up our navigation and inside the
navigation we just simply add this to a bar button items push from right, push
from left, okay. We have two selectors here first one is the basic pushed from right
navigation controller is pushed as usual we
the navigation controller dot push view controller animated, okay. Now we want to
have a push from left bar button item tapped where we want to present the pushed
from a left navigation view controller, okay. And for that we are going to create an
extension. Let's just scroll all the way down here and here we have push view
controller from left and I'm just going to paste the code in and go through it
with you line by line, okay. As you can see we are creating a CA transition.
Now the transition takes care of everything. We have a duration of 0.5 seconds and the
type is push the subtype now this is important a transition subtype of from left.
So it is coming from left. Timing function it is ease in, ease out yet that
is just for making it more fluent and then we add that transition to the
windows layer and of course we push the view controller and make sure that you
set the animated to false because basically the animation is this
transition. Now while we are at it let's take a look at the pop view controller
to left that is popping the view controller and we are going to paste
that in again and we want to change the from left to from right and that is it.
We are done, okay. Let's just hit command B to get rid of that error and yeah we
want, yeah we are not done my fault we want to pop view controller animated
false, okay. And those are the two changes that need to be done to pop
view controller, okay. Now let's go back to our navigation view controller and
use these functions. So push from left bar button item tapped we are going to type
in navigation controller dot and
now we want to push from left and the controller is our created view
controller. Okay and before we run this let's add in the pop view controller
functionality too and for that we need to go to our pushed from left
navigation view controller and this is it and as you can see here we have our
bar button item and the selector is this function and what we want to do is
simply type in navigation controller and pop view controller to left and that
is it, okay. Let's test it out and see all of this in action.
Okay, here we go with the right again, basic stuff we already know that.
Now let's push from left, there we go and now let's pop to left there we go, pretty
simple and yeah again you might use this or you might dislike it if you wanted to
but if you want to use it you can now with the help of this cool extension.
Now I hope you enjoyed this video if you did go ahead and give it a thumbs up,
subscribe to the channel and hit that notification bell to get notified of new
videos and they are coming and you did have a peek to the next one we are going
to hide the navigation item. Well the background of it. So I will see you in the next video.