侧滑菜单(一),View移动和收缩

下文主要讲述如果制作两个View,通过叠加两个view ,
底层view作为菜单层
上层作为内容显示层
通过移动内容层,达到菜单层的显示和关闭。
如下代码所示:

//  ViewController.h
//  Created by shenye on 16/4/8.
//  Copyright © 2016年 www.maomao365.com All rights reserved.
#import 

@interface ViewController : UIViewController
{
    UIView *leftView;
    UIView *mainView;
    NSInteger *x;
    NSInteger *y;
}

@end


//
//  ViewController.m
//  Created by shenye on 16/4/8.
//  Copyright © 2016年  www.maomao365.com All rights reserved.
//

#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    x =0;
    y =0;
     //生成第一层(菜单层) view 并设置view 顺序 颜色
    
    leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [leftView setBackgroundColor:[UIColor blueColor]];
    //添加菜单层
    [self.view addSubview:leftView];
    
    
    mainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height)];
    [mainView setBackgroundColor:[UIColor redColor]];
    //添加 菜单展开和关闭按钮
    UIButton *btnTmp2 = [[UIButton alloc]initWithFrame:CGRectMake(mainView.frame.origin.x,mainView.frame.origin.y+10, 100, 30)];
    [btnTmp2 setTitle:@"===" forState:UIControlStateNormal];
    [btnTmp2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnTmp2 setBackgroundColor:[UIColor whiteColor]];
    [btnTmp2 addTarget:self action:@selector(movBtn) forControlEvents:UIControlEventTouchDown];
    [mainView addSubview:btnTmp2];
    
    //添加数据显示层
    [self.view addSubview:mainView];
    
}

 //按钮事件 层的展现和关闭
-(void)movBtn {
    NSLog(@"移动按钮!");
    if(x >0)
    {
        x =0;
        y =0;
    }else
    {
        x = x +30;
        y = y +10;
    }
    [mainView setFrame:CGRectMake((long)x,(long)y,self.view.frame.size.width, self.view.frame.size.height)];
    
}
@end