Hey everybody welcome to the last video in the firebase section.
Amazing work so far building this app we just have one last video to go.
And in this one we're basically just going to do a quick view controller extension that's going to change
the way that view controllers present.
If you choose to use this function from the extension and it's going to simulate the same kind of transition
as a navigation controller where it will animate from left to right and right to left instead of popping
up straight over the front that's pretty cool.
Very efficient and we're going to go ahead and build it now.
So open up your X code project right click on extensions and click new file swift file is fine and we're
going to call this UI View Controller XTi for extension click Create and we're going to go ahead and
we need to import you kit because this actually has to do with you Ibut controller which is part if
you like it.
Next go ahead and type extension you view controller.
And we're going to write two functions.
Function one is going to be called phunk present detail meaning like present a detailed controller and
we're going to basically pass in a view controller to present of Type II controller.
Now if this looks familiar to you that's because this comes from Normally in you view controller you
can call present and you can present another view controller on top of it.
We're going to use the same parameter as present does but this is this is going to be for present detail.
Now we need to make a custom transition of type C-A transition and C.A. comes from Core Animation.
So let's go ahead and let's create a constant that's going to hold this animation.
Go ahead and type let.
Transition.
Equal equals.
See a transition.
Go ahead and instantiate it.
And now we need to set up the settings we want this transition to take 0.3 seconds.
Just like a UI navigation controller.
So go ahead and type transition.
Duration equals zero point three.
Next we're going to ask it to set its type.
So we're going to type transition type and it's going to be equal to KCA K meaning it's coming from
Core Animation transition and you can see there's a ton of different ones you can do a lot of really
cool transitions with this and you can play around with it if you want but I'm just going to go with
push because that's going to push the controller from a certain direction.
Now we need to tell it what direction.
So we're going to call it transition subtype and the subtype is KCA transition from a right OK because
when we present it we wanted it to present from the right side and slide over to the left side.
OK.
Very cool.
And then we're going to go ahead and add this transition to the layer of The View Controller window.
So go ahead and call self view.
Meaning the view of The View Controller window to the UI window layer add and you'll see there you can
add an animation that animation is transition.
It's a type of C-A animation if you look closely.
So the key this is just from deep within Iowa.
We can call k see a transition and that tells it that this is a transition of type C.A. transition.
So now we have successfully added the transition.
Now we're just going to go ahead and call the default present controller from Iowa s and the view controller
to present will be the one we pass in.
So go ahead and give it a controller to present.
We want it to be animated.
But the interesting thing is we've already set up the animation so we're going to dismiss or we're going
to not include the default iOS animation and we're just going to go ahead and call false to completion.
We don't care we're not going to use it.
So that is how we're going to present our detailed controller and I'm so excited I want to go try it
right now let's go into groups AVC and where we called present.
We're going to check now we should have the ability to call present detail the view controller to present
will just be group feed visi.
So let's try that with our new extension Let's see how it works and let's build and run and try it out
in our simulator.
Here we go.
Sweet it's installing OK it's opening.
Now when I select my table you sell here you should see it slide over instead of sliding up.
Let's try it.
Look at that.
That's just like a UI navigation controller.
Now of course if I click this it's still going to dismiss it like it used to but we get a cool UI navigation
controller styled animation.
Very very cool.
Now we're going to go set up the other function which is going to allow us to dismiss it to the left.
OK.
So go back to you you controller extension and we're going to go ahead and write another function called
dismiss detail.
Go ahead and type phunk dismiss detail.
And inside this function we're basically going to do the exact same thing except we're going to dismiss
the view controller instead of presenting it.
So I'm actually just going to copy this and paste it and then I'm going to change from right to from
left because that's basically what we're doing is the same thing just from the left.
Now instead of calling present we're instead going to call dismiss and just like before we're going
to override default transition style so we're just going to call false because otherwise it will try
to present it like Iowa does.
And for the completion we don't care we're going to say nil.
Now we can dismiss any view controller just like a UI navigation controller so to do this we have to
go to group feed Visi and we need to look to see where our cancel button or our back button goes.
OK.
Earlier we called just a regular iOS standard dismiss but now we can call dismiss.
Oh you know what.
Looks like we might need to build this to show for it to show up.
Looks like it's not yet there.
OK good.
There it is.
Dismiss detail that's all.
Let's build and run it.
Let's see how it works.
And guys after that we can call this app finished.
Totally done for the most part with exception of what I will challenge you to do in the next video.
But let's go into groups.
Click on nerd herd and when I click this button it should transition back to the left like we want.
Oh look at that.
So cool.
So it looks like it works.
We can open our groups.
We can load our feed we can make a post from our account.
We have a profile page with an unfinished table view.
Wink wink.
In the next video I'm going to give you a challenge to see how you can extend this app and make it even
more incredible.
Thank you guys so much for going through this section of the course.
Amazing work this app would be an amazing portfolio piece by the way to show a potential employer so
I would highly recommend that you do that.
Let's head over to the next video for your challenge.