#import "CXDSideMenuController.h"#import "AllControllerDispatchTool.h"#import "SideHeaderView.h"#import "Masonry.h"#import "LoginViewController.h"@interfaceCxdsidemenucontroller ()//Background Matte@property (Strong, nonatomic) UIView *Backgroundimageview;//content View@property (Strong, nonatomic) UIView *Contentview;//Enter the number of the view@property (Assign, nonatomic) Nsuinteger Selectindex;//Side bar Headerview@property (Strong, nonatomic) Sideheaderview *Headerview;@end@implementationCxdsidemenucontroller#pragmaMark-Initialize Method +(instancetype) sharesidemenu{StaticCxdsidemenucontroller *SIDEMENUVC =Nil; Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{SIDEMENUVC= [SelfNew]; }); returnSIDEMENUVC; }//Wake-Up Side menu method+ (void) Opensidemenufromwindow: (UIWindow *) window{//each invocation ensures that the side menu that wakes up is the only oneCxdsidemenucontroller *sidemenu =[Cxdsidemenucontroller Sharesidemenu]; [Window AddSubview:sideMenu.view]; //after wake up, you need to move the side menu into the current view[UIView animatewithduration:0.5animations:^{cgrect rect=SideMenu.contentView.frame; Rect.origin.x=0; SideMenu.contentView.frame=rect; SideMenu.backgroundImageView.alpha=0.5; }];}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{ //Slide-off menu retract[self closesidemenu]; }//Side-by-side menu retract (separately extracted, easy to click on the TableView row corresponding response)- (void) closesidemenu{//how to get a side-slip menu that has been awakened[UIView animatewithduration:0.5animations:^{ //Slide-off menu retractCGRect rect =Self.contentView.frame; Rect.origin.x= -Rect.size.width; Self.contentView.frame=rect; Self.backgroundImageView.alpha=0; } Completion:^(BOOL finished) {//to remove the slide-by menu from the current view[Self.view Removefromsuperview]; //go to the appropriate selection screen[Allcontrollerdispatchtool Createviewcontrollerwithindex:_selectindex]; }];}#pragmaMark-Life cycle-(void) viewdidload {[Super viewdidload]; //Build Interface[Self.view AddSubview:self.backgroundImageView]; [Self.view AddSubview:self.contentView]; [Self.contentview AddSubview:self.headerView]; //Add constraint//because the _headerview is loaded on the Contentview, the Headerview constraint is calculated based on the Contentview, so weakself must be the Contentview type in the block __weaktypeof(self.contentview) weakself =Self.contentview; [_headerview mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.left.equalTo (weakself.mas_left); Make.right.equalTo (Weakself.mas_right); Make.top.equalTo (Weakself.mas_top); Make.height.equalTo ( the); }];}#pragmaMark-Lazy Loading-(UIView *) backgroundimageview{if(!_backgroundimageview) {_backgroundimageview=[[UIView Alloc]initwithframe:[uiscreen mainscreen].bounds]; _backgroundimageview.backgroundcolor=[Uicolor Blackcolor]; _backgroundimageview.alpha=0; } return_backgroundimageview;}-(UIView *) contentview{if(!_contentview) {CGRect rect=[UIScreen mainscreen].bounds; _contentview= [[UIView alloc] Initwithframe:cgrectmake (-rect.size.width*0.8,0, rect.size.width*0.8, Rect.size.height)]; _contentview.backgroundcolor= [Uicolor colorwithred:0.2Green0.2Blue0.2Alpha1]; } return_contentview;}-(Sideheaderview *) headerview{if(!_headerview) {_headerview=[[Sideheaderview alloc] init]; [_headerview.headimagebtn addtarget:self Action: @selector (Movetologinview) forControlEvents: UIControlEventTouchUpInside]; [_headerview.usernamebtn addtarget:self Action: @selector (Movetologinview) forControlEvents: UIControlEventTouchUpInside]; } return_headerview;}- (void) movetologinview{Loginviewcontroller*LOGINVC =[[Loginviewcontroller alloc] init]; [Self PRESENTVIEWCONTROLLER:LOGINVC animated:yes completion:nil];}
PS: Invoke the slide-through menu process via a button
PS: Part of the code, for reference only
iOS slip-on interface implementation