The realization of skidding

Source: Internet
Author: User

Recently realized a slide-off function of the demo, take it out for everyone to share.

The principle of this side-slip implementation is a master controller, and a secondary controller. When the slide-slip effect needs to be displayed, the view of the host controller shrinks and slides to the side, and the parent controller's view is added to the window, which results in a side-slip effect.

1. Create a class, inherit Uinavigationcontroller, and override the constructor method

-(instancetype) Initwithrootviewcontroller: (uiviewcontroller *) Rootviewcontroller;

Initializes the instance that needs to be initialized in the construction method.

2, provide two methods

-(void) OpenView open slide

-(void) closeview off slide

The main code

-(void) openview{[Self.view.window insertsubview:_leftmenu.view atindex:0]; [UIView animatewithduration:0.5animations:^{cgaffinetransform Newtransform=Cgaffinetransformscale (self.view.transform, scale, scale);        [Self.view Settransform:newtransform]; CGRect rect=Self.view.frame; Self.view.center= Cgpointmake (self.view.frame.origin.x + self.view.frame.size.width/2, SELF.VIEW.FRAME.ORIGIN.Y + self.view.frame.size.height/2); Rect.origin.x= Screen_max_weith- -; RECT.ORIGIN.Y= -; Self.view.frame=rect;    }]; [Self.view.window Addsubview:_rightview];}-(void) closeview{[UIView animatewithduration:0.5animations:^{cgaffinetransform Newtransform= Cgaffinetransformscale (Self.view.transform,100.0f/(Scale * -),100.0f/(Scale * -));        [Self.view Settransform:newtransform]; CGRect rect=Self.view.frame; Self.view.center= Cgpointmake (self.view.frame.origin.x + self.view.frame.size.width/2, SELF.VIEW.FRAME.ORIGIN.Y + self.view.frame.size.height/2); Rect.origin.x=0; RECT.ORIGIN.Y=0; Self.view.frame=rect; } Completion:^(BOOL finished) {[_rightview Removefromsuperview]; }];}

3, provide a method for jumping page

-(void) Pushcontroller: (uiviewcontroller *) Viewcontroller;

The above is the main logic of the demo slide implementation.

Effects such as

Demohttps://github.com/lushui/leftmenu

The realization of skidding

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.