iOS drawer effect and side menu

Source: Internet
Author: User

iOS drawer effect and side menu source 1, Effect demo 1. Drawer Effect Demo

1. Side Menu Demo

2, the use of instructions to construct the method initialization
Construction method (left Controller & right controller & background picture)-(instancetype)Initwithleftcontroller:(uiviewcontroller *)Leftcontroller Andmaincontroller:(uiviewcontroller *)Maincontroller Andrightcontroller:(uiviewcontroller *)Rightcontroller Andbackgroundimage:(UIImage *)image;///Construction Method(Left Controller & right Controller)-(instancetype)Initwithleftcontroller:(uiviewcontroller *)Leftcontroller Andmaincontroller:(uiviewcontroller *)Maincontroller Andrightcontroller:(uiviewcontroller *)rightcontroller;///Construction Method(Left Controller & right Controller)-(instancetype)Initwithleftcontroller:(uiviewcontroller *)Leftcontroller Andmainview:(uiviewcontroller *)maincontroller;///Construction Method(right Controller)-(instancetype)Initwithrightview:(uiviewcontroller *)Rightcontroller Andmainview:(uiviewcontroller *)Maincontroller;
View Control method
/// 恢复位置-(void)showMainView;/// 显示左视图-(void)showLeftView;/// 显示右视图-(void)showRighView;
Property attribute
///main view hidden after display scale ( 0~1)   @property  (nonatomic , assign ) cgfloat  Otherscale; ///main view ratio (0~1)   @property  (nonatomic , assign ) cgfloat  Mainscale; ///sliding speed coefficient-recommended between 0.5-1. The default is 0.5   @property  (assign , nonatomic ) cgfloat  SPEEDF; ///whether to allow click View to restore View location. The default is yes   @property  (strong ) UITapGestureRecognizer *sidesliptapges;  
3. How to use APPDELEGATE.M
- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions {//1. Create Window     Self. Window= [[UIWindowAlloc] Initwithframe:[uiscreen Mainscreen]. Bounds];//2. Create a controllerMaincontroller *main = [[Maincontroller alloc] init];    Leftcontroller *left = [[Leftcontroller alloc] init]; Rightcontroller *right = [[Rightcontroller alloc] init];//3. Create with controllerJrmenucontroller *controller = [[Jrmenucontroller alloc] Initwithleftcontroller:left andmaincontroller:main    Andrightcontroller:right]; Controller. Mainscale=0.8; Controller. Otherscale=0.6; Controller. SPEEDF=0.6;//4. Setup and Controller     Self. Window. Rootviewcontroller= Controller;//5. Show Window[ Self. WindowMakekeyandvisible];return YES;}
4. Summary of Knowledge points 1. Swipe gesture direction judgment
// 滑动方向typedef NS_ENUM(NSInteger, CameraMoveDirection) {    kCameraMoveDirectionNone,    kCameraMoveDirectionUp,    kCameraMoveDirectionDown,    kCameraMoveDirectionRight,    kCameraMoveDirectionLeft,};
//创建滑动手势        UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
#pragma mark-determine the direction of the slide- (void) Handleswipe: ( Uipangesturerecognizer *) Gesture {Cgpointtranslation = [gesture Translationinview: Self. View];if(Gesture. State= = Uigesturerecognizerstatebegan) { Self. Direction= Kcameramovedirectionnone; }Else if(Gesture. State= = Uigesturerecognizerstatechanged && Self. Direction= = Kcameramovedirectionnone) {//Get directions         Self. Direction= [ SelfDeterminecameradirectionifneeded:translation]; }if( Self. Direction= = Kcameramovedirectionright && Self. Leftcontrol!=Nil) {        [ SelfHandlepan:gesture]; }if( Self. Direction= = Kcameramovedirectionleft && Self. Righcontrol!=Nil) {        [ SelfHandlepan:gesture]; }}
//Get directions-(Cameramovedirection) determinecameradirectionifneeded: (Cgpoint) translation{if( Self. Direction! = Kcameramovedirectionnone)return  Self. Direction;if(Fabs (translation. x) > Gestureminimumtranslation) {BOOLGesturehorizontal =NO;if(translation. Y==0.0) Gesturehorizontal =YES;ElseGesturehorizontal = (Fabs (translation. x/translation. Y) >5.0);if(gesturehorizontal) {if(translation. x>0.0)returnKcameramovedirectionright;Else                returnKcameramovedirectionleft; }    }Else if(Fabs (translation. Y) > Gestureminimumtranslation) {BOOLGesturevertical =NO;if(translation. x==0.0) gesturevertical =YES;ElseGesturevertical = (Fabs (translation. Y/translation. x) >5.0);if(gesturevertical) {if(translation. Y>0.0)returnKcameramovedirectiondown;Else                returnKcameramovedirectionup; }    }return  Self. Direction;}
2. Sliding gestures and tableview sliding coexistence
#pragma mark - UIGestureRecognizerDelegate// 设置手势 滑动 和 tableView 滚动并存- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {    if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {        returnYES;    }    returnNO;}
3. Tableviewcell Split line setup throughout the TableView (supplemental)
//cell line split line setup- (void) TableView: (UITableView*) TableView Willdisplaycell: (UITableViewCell*) Cell Forrowatindexpath: (Nsindexpath*) Indexpath {if([Cell Respondstoselector:@selector(Setseparatorinset:)])    {[Cell Setseparatorinset:uiedgeinsetszero]; }if([Cell Respondstoselector:@selector(Setlayoutmanager:)])    {[Cell Setlayoutmargins:uiedgeinsetszero]; }}- (void) Viewdidlayoutsubviews {if([ Self. TableViewRespondstoselector:@selector(Setseparatorinset:)]) {         [ Self. TableViewSetseparatorinset:uiedgeinsetsmake (0,0,0,0)]; }if([ Self. TableViewRespondstoselector:@selector(setlayoutmargins:)]) {        [ Self. TableViewSetlayoutmargins:uiedgeinsetsmake (0,0,0,0)]; }}

iOS drawer effect and side 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.