Build an animated Burger button
The burger button and slide-out menu may be the most polarized interface element in the industry. Apple's ardent supporters oppose the burger buttons and the corresponding slide-out menus, saying that designers (and engineers, product managers and CEOs) like to accumulate as much as possible in that space because you have a lot of vertical spaces.
I can't say I disagree because the user test shows that the user doesn't actually use the slide-out menu, but maybe I'm a hypocrite because I'm still using a burger button in my iphone app interesting, so it seems like I'm a problem too! Anyway, if you're going to use a burger button, you have to make it interesting and pleasing to people to click on.
So what is the basic element of a burger button? Typically there are three horizontal bars to describe the general state, and if you want to be more subtle, you can change the bar to an X-shape when the menu is open. Of course, pop is used to make the user interface developer refined, so why not add some animation to the transition?
Take a little look at what we're building.
At first, we had a round black button with a hamburger-shaped line in the middle. When the button is clicked, it animates to a slightly smaller size. But at the end of the click, the line will animate the city red X. When you click the X state, the animation returns to its original color and position. This is a remarkably simplified explanation of what happened, let's take a look at the code.
//Add the Burger button to the screen Self. Hamburgerbutton= [Dtctestbutton Buttonwithtype:uibuttontypecustom]; [ Self. HamburgerbuttonAddTarget: SelfAction@selector(Didtaphamburgerbutton:) forcontrolevents:uicontroleventtouchupinside]; Self. Hamburgerbutton. BackgroundColor= [UicolorBlackcolor]; [ Self. HamburgerbuttonSetframe:cgrectmake ( $, $, Max, Max)]; Self. Hamburgerbutton. Layer. Cornerradius= the; [ Self. WindowAddsubview: Self. Hamburgerbutton];
We set the burger button to the @property of the class so that we can invoke it through Self.hamburgerbutton. It uses the same button subclass we created in the previous example, so that we can get a good sense of elasticity as soon as the user clicks. We also set the button when the user releases the button when they click on the finger when the event is UIControlEventTouchUpInside lowered with our method-didtaphamburgerbutton:. We also set the button to black and have rounded corners.
Here is what we have now.
It's time to add our hamburger line as a sub-view to the button.
CGFloat sectionwidth = the;CGFloat sectionheight = One;Add upper, middle, and lower Hamburg lines self. Top= [[UIView alloc] Initwithframe:cgrectmake (self. Hamburgerbutton. Bounds. Size. Width/2-sectionwidth/2, +, Sectionwidth, Sectionheight)];Self. Top. BackgroundColor= [Uicolor Whitecolor];Self. Top. userinteractionenabled= NO;Self. Top. Layer. Cornerradius= sectionheight/2;[Self. HamburgerbuttonAddsubview:self. Top];Self. Middle= [[UIView alloc] Initwithframe:cgrectmake (self. Hamburgerbutton. Bounds. Size. Width/2-sectionwidth/2, the, Sectionwidth, Sectionheight)];Self. Middle. BackgroundColor= [Uicolor Whitecolor];Self. Middle. userinteractionenabled= NO;Self. Middle. Layer. Cornerradius= sectionheight/2;[Self. HamburgerbuttonAddsubview:self. Middle];Self. Bottom= [[UIView alloc] Initwithframe:cgrectmake (self. Hamburgerbutton. Bounds. Size. Width/2-sectionwidth/2, About, Sectionwidth, Sectionheight)];Self. Bottom. BackgroundColor= [Uicolor Whitecolor];Self. Bottom. userinteractionenabled= NO;Self. Bottom. Layer. Cornerradius= sectionheight/2;[Self. HamburgerbuttonAddsubview:self. Bottom];
I've set up some of the number variables we'll be reusing in this code CGFloat . I added three UIView objects to the main burger button, each of which is a rounded rectangle with a white background. They are placed in the horizontal center of the big burger button and are separated vertically. The most interesting part of this code is that I set the Userinteractionenabled property of each view to No. If we do not do this to these views, if you click the button directly, it will engulf the touch event and will not be passed on to the actual full burger button. Here's what it looks like now.
Now don't add any code, because this button is the subclass type we created in the previous example UIButton DTCTestButton , and there are some animations already.
Finished viewing the integration set: Https://github.com/Cloudox/Motion-Design-for-iOS
All rights reserved: Http://blog.csdn.net/cloudox_
Motion Design for IOS (43)