第一步:
在AppDelegate.m里
首先导入头文件 #import “ViewController.h”
ViewController *vc = [[ViewController alloc]init];
vc.title = @"抽屉";
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = nav;
第二步:
在ViewController.m
// 左视图
@property (nonatomic,strong) UIView *leftView;
viewDidLoad 里
// A 视图 本身view的背景颜色
self.view.backgroundColor = [UIColor redColor];
// B 视图 根视图背景颜色
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor cyanColor];
// 设置左视图是否可以与用户交互
self.leftView.userInteractionEnabled = YES;
self.leftView.frame = CGRectMake(-80, 64, self.view.frame.size.width, self.view.frame.size.height - 64);
// [self.navigationController.view.superview addSubview:self.leftView];
//
// [self.navigationController.view.superview sendSubviewToBack:self.leftView];
//
//设置左视图的大小
// self.leftView.frame = self.view.frame;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(left)];
}
-(void)left{
// 点击导航按钮 设置页面相对于原来位置变换的位置
//CGAffineTransformMakeTranslation; //相对于屏幕平移的距离
// CGAffineTransformMakeScale; //平移后相对于原来的大小 这个是按比例计算的
[UIView animateWithDuration:0.25 animations:^{
self.navigationController.view.transform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(380, 0), CGAffineTransformMakeScale(0.7, 1.0));
}];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//切换动画
[UIView animateWithDuration:0.25 animations:^{
self.navigationController.view.transform = CGAffineTransformIdentity;
self.leftView.transform = CGAffineTransformIdentity;
}];
[super touchesBegan:touches withEvent:event];
}
运行效果: