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