Thursday, January 3, 2019

How We Created Guillotine Menu Animation for iOS

Have you at any point asked why a sidebar in applications must be a "side" bar? Why not to make it a "topbar," or a "bottombar," or a "cornerbar," and so on.?

Another enlivened pattern in the age of route bars is the thing that we will discuss this time. Movements are fun however above all, they are helpful. They can change your mindset, make your item appealing, and enhance client encounter. Here is the manner by which our architect Vitaly Rubtsov thought of this extraordinary thought:

"Occasionally every planner gets exhausted. All these fixes, cuts, determinations – they leave almost no space for creative ability. In these minutes I have a craving for opening my Adobe After Effects and making something intriguing.

When I began considering what to make this time, I got myself on a felt that an ordinary sidebar menu which unfortunately escapes the left piece of the screen moving all substance to one side, is so agonizingly exhausting! Consider the possibility that a sidebar turns into a topbar. It will drop down from the highest point of the page and turn remarkably. Sounds like fun, doesn't it?"

Vitaly's topbar movement was actualized in Swift by our iOS designer Maksym Lazebnyi, who gave it an amusing name Guillotine Menu – the manner in which it drops down from the best helps a bit to remember an infamous murdering machine. All things considered, our activity is an exceptional element too!

Look at it on Dribbble and GitHub.



How we built up the Guillotine Menu

Truth be told, our iOS group saw heaps of approaches to actualize the liveliness. We picked the one that enables a designer to tweak a menu every way under the sun ideal from the Storyboard.

To make our changing activity we assembled a subclass of the UIStoryboardSegue and a custom movement controller. Essentially, this is all you requirement for this kind of a menu activity, except if you need to make it look extremely wonderful. We without a doubt did! That is the reason we made a few extra classes.

By and large, you require three classes and one UIView augmentation to make the movement. Here are these folks:

GuillotineMenuSegue. It's a UIStoryboardSegue which is a subclass of UIStoryboardSegue. We utilized it for a modular introduction of the menu and furthermore to display the activity controlled by GuillotineMenuTransitionAnimation class. GuillotineMenuSegue enables us to add some straightforwardness to the menu too (not this time however).

GuillotineMenuTransitionAnimation. This class exhibits a perspective of the GuillotineMenuViewController of our custom liveliness.

GuillotineMenuViewController. It's a UIViewController subclass for the menu.

We additionally utilized UIViewExtension to set four requirements for a subview with the goal that it could fit a superview.

Presently we should take a gander at each class independently.

Guillotine Menu Segue

There is nothing unique in this class, so we'll just make reference to two or three things.

In the overriden init technique we check if a goal see controller accommodates a convention for GuillotineAnimationProtocol (we'll talk about this convention somewhat later). In the overriden perform technique we set self as a progressing delegate.

In the representative strategy animationControllerForPresentedController we set the hold relationship among self and the GuillotineMenuViewController to keep it alive while it's on screen.

GuillotineMenuTransitionAnimation

Here's the place all the enchantment occurs!

At first we considered UIView.animateWithDurationusingSpringWithDamping and initialSpringVelocity. However, after a more critical take a gander at the liveliness we altered our opinion. The perspective of the menu needs to deliver an impacting impact with a bounce back when it's striking the left outskirt of the superview, which it wouldn't do should we utilize the technique animateWithDuration (it would spring through the fringe of the superview).

That is the reason we picked UIDynamicAnimator.

So as to make the activity, GuillotineMenuTransitionAnimation class must acclimate UIViewControllerAnimatedTransitioning convention. As you most likely are aware, it has 2 techniques:

func. transitionDuration. Span of the activity does not make a difference much for our situation, so we can restore whenever interim.

func animateTransition is considered when the menu needs to open or close.

How we determined the area of the liveliness

We ought to likewise know an exact area of the liveliness. GuillotineMenuTransitionAnimation requires GuillotineMenuViewController to give the directions of the focal point of the menu catch since it'll be the grapple point for a turn. Very are some more properties we require from the GuillotineMenuViewController, so we chose to make a convention that the GuillotineMenuViewController should acclimate:

navigationBarHeight() - GuillotineMenuViewController begins to demonstrate the movement when it's turned by 90° while covering a route bar. We have to set the situation of the perspective of the GuillotineMenuViewController to CCPoint(0, navigationBarHeight)

anchorPoint() is a turning place for our activity and along these lines, a focal point of the menu catch of the GuillotineMenuViewController.

func hostTitle() is utilized to approach the GuillotineMenuViewController for the title of the host View Controller.

How we executed the drop down and turn

To execute the drop down and turning of the activity, we utilized UIDynamicAnimator with four practices:

UIPushBehavior is a power that pulls the view towards the base or the highest point of the screen contingent upon whether we appear or expel the liveliness.

UIAttachmentBehavior resembles a "nail" which holds the view in the focal point of the menu catch.

UICollisionBehavior. We made a limit which covers the zone from the center of the tallness of the superview to its base left corner. It's required for the GuillotineMenuViewController to slam into the superview toward the finish of the turning way.

UIDynamicItemBehavior is expected to make the view bounce back after the crash.

Fundamentally, the activity begins with the GuillotineMenuViewController's view turning by 90° with the assistance of CGAffineTransformRotate. We set its edge position to CCPoint(0, navigationBarHeight). At that point, we add the view to the variety of things for each UIDynamicBehavior.

UIDynamicAnimator keeps vitalizing the menu until the point when all powers made by the practices get adjusted.

By utilizing UIDynamicAnimatorDelegate convention we can illuminate the view controller about the consummation of the movement. To do this, we call a strategy endAppearanceTransition().

The precarious part here was setting up the anchorPoint. For a right movement it requires to be situated at an equivalent separation from the left half of the GuillotineMenuViewController's view and the base of the route bar. Additionally, it ought to legitimately change its position if a gadget is turned. In any case, the issue is that GuillotineMenuTransitionAnimation class calls the technique anchorPoint() delegate before a strategy viewDidLayoutSubviews() is called.

We needed to hardcode the situation of catches at the scene gadget introduction.

UIViewExtension

It's a basic augmentation which adds imperatives for the subview to fit the superview limits. UIViewExtension is practically obvious.

Guillotine Menu View Controller

This view controller can be subclassed or changed without any preparation for any sort of customization. The primary concern is that it ought to adjust the GuillotineAnimationProtocol.

How might you modify the movement?

Don't hesitate to tweak the perspective of the menu every which way! Simply make a custom GuillotineMenuSegue from your host see controller to your menu see controller that accommodates ActivityAnimationProtocol in the interface manufacturer and you are prepared to go.

To be completely forthright, I began making this activity believing it's very straightforward and there is a practically zero test in it. In any case, presently we should concede that there is an enormous potential for iOS designers. We discovered that our liveliness could likewise be executed as a straightforward vivified see or a subclass of UINavigationController with a custom route bar. We expect to refresh the segment by making an entire subclass of UINavigationViewController with custom exchange movements.

No comments:

Post a Comment