iOS development--Encapsulate your own drop-down menu

Source: Internet
Author: User

Train of thought 1, picture stretching:
UIImage *image = [UIImage imageNamed:@"popover_background"];        image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(240240) resizingMode:UIImageResizingModeStretch];

-resizableImageWithCapInsets:resizingModeThe second parameter of the method, the adjustment mode is divided into two kinds, tiling and stretching. In this case, the frame with the arrows in the background will be properly surrounded by the size of the content, using stretching.

2. Circular transition Animation

The specific implementation can refer to this blog: iOS development-circular transition animation. Put the code here.

CGRect originalrect = CGRectMake (point. x, point. Y,1,1);Self. Startpath= [Uibezierpath Bezierpathwithovalinrect:originalrect];Cgpoint extremepoint = Cgpointmake (point. x, point. Y+ Contentview. Frame. Size. Height);CGFloat radius = sqrtf (extremepoint. x* Extremepoint. x+ Extremepoint. Y* Extremepoint. Y);Uibezierpath *endpath = [Uibezierpath bezierpathwithovalinrect:cgrectinset (Originalrect,-rad IUS,-radius)];Self. Shapelayer= [Cashapelayer layer];Self. Shapelayer. Path= Endpath. Cgpath;Self. Layer. Mask= Self. Shapelayer;if (animated) {cabasicanimation *animation = [Cabasicanimation animationwithkeypath:@"Path"];Animation. Fromvalue= (__bridge ID) (self. Startpath. Cgpath);Animation. Tovalue= (__bridge ID) (Endpath. Cgpath);Animation. Duration=0.3F;[Self. ShapelayerAddanimation:animation forkey:@"Begin"];}
3. Other

①view's Hierarchical relationship:

There are two main controls, Contentview for the user incoming view, is generally a table to give, the user needs to specify the Contentview of the width of the height.
The other is that ImageView acts as a background image, and the ImageView as a container for the user's incoming Contentview,
The entire control is a view, the background is transparent, mask use, when the menu is open when the user click on the background will make the menu retract.
When the user passes in the Contentview, resets its origin, and updates the size of the imageview so that it encloses the entire contentview.
Finally, add this whole to the window to make sure the menu is on top.

② Coordinate system transformation
A coordinate system transformation is required for the user to pass in a control to determine where the menu is displayed. There are also records in the previous blog about coordinate system transformations, leaving a simple conclusion:
[Viewa convertRect:viewA.bounds toview:viewb]-get Viewa viewb in bounds coordinate system.

Distinguish multiple animation objects in ③caanimationdelegate

First, set the flag key for the animation when you add it:
[self.shapeLayer addAnimation:animation forKey:@"end"];
In the proxy method, take the following layer method:

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {    if (anim == [self.shapeLayer animationForKey:@"end"]) {        self.shapeLayer.pathself.startPath.CGPath;        [self removeFromSuperview];    }}
Code

Source

iOS development--Encapsulate your own drop-down menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.