Custom Side Menu With Transitioning Delegate Part 2

Nattapong Unaregul
2 min readDec 27, 2018

--

Hi Guys. As promising, I come back with part 2. Before coding, Lets overview mechanism of Presentation Controller. I knew it is a boring part to understand the machinism but believe me when you really do understand the concept of it. You will have no fear about creating nice transition at all.

For me, Presentation Controller is an object to make the transition has much more effects and can add custom view between From and To viewControllers during presentation without mess around the viewControllers. So it keep the viewControllers clean and organisable. Any custom views inside Presentation Controller object can add their own animation participate in transition of ViewControllers which mean they can be animated alongside with transition’s viewControllers simultaneously.

So the new hero has arrived called Transition Coordinator. It is able to participate in an ViewControllers’s animation with its own custom view.

Figure 1

Let’s get in action, Create class named BHMenuPresentation. setupDimingView() function is to create shadow under presented viewController(To View). It has a tap gesture to handle user’s tapping to perform dismiss action.

Put the file in the following structure

Next, We overide both presentationTransitionWillBegin and dismissialTransitionWillBegin function. As the functions’s name tell so, These functions fire before transition happens. We get an coordinator object to perform an animation along with main animation (ViewController’s animation).

For presentation action, We will show the shadow view.

For dismissal action, We will hide the shadow view.

The context object inside closure coordinator.animator is called UIViewControllerTransitionCoordinatorContext which contain information same as UIViewControllerContextTransitioning in Animator object i have shown you in part 1.

Finally, We replace presentationController function in BHMenuTransitionManager with code below.

Build and run to see the result. Try to tap on shadow view. It will perform dismiss action.

Stay tune for part 3. The final part.

--

--