#import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) UIViewController *rootViewController;@property (nonatomic, strong) UIView *maskLayer;@property (nonatomic, strong) UIButton *closeButton;@property (nonatomic, strong) UIView *popView;@end@implementation ViewController- (UIViewController *)rootViewController { if (!_rootViewController) { _rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController; } return _rootViewController;}- (UIView *)maskLayer { if (!_maskLayer) { _maskLayer = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; _maskLayer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; _maskLayer.alpha = 0; _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; _closeButton.frame = _maskLayer.bounds; [_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside]; [_maskLayer addSubview:_closeButton]; } return _maskLayer;}- (UIView *)popView { if (!_popView) { _popView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/2)]; _popView.backgroundColor = [UIColor whiteColor]; } return _popView;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (IBAction)show:(id)sender { [self open];}// 开启- (void)open { [self.rootViewController.view addSubview:self.maskLayer]; [[UIApplication sharedApplication].keyWindow addSubview:self.popView]; [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor blackColor]; CGRect frame = self.popView.frame; frame.origin.y -= frame.size.height; [UIView animateWithDuration:0.3 animations:^{ self.rootViewController.view.layer.transform = [self getFirstTransform]; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ self.rootViewController.view.layer.transform = [self getSecondTransform]; self.maskLayer.alpha = 1; self.popView.frame = frame; } completion:^(BOOL finished) { }]; }];}// 关闭- (void)close { CGRect frame = self.popView.frame; frame.origin.y += frame.size.height; [UIView animateWithDuration:0.25 animations:^{ self.rootViewController.view.layer.transform = [self getFirstTransform]; self.popView.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.2 animations:^{ self.rootViewController.view.layer.transform = CATransform3DIdentity; self.maskLayer.alpha = 0; } completion:^(BOOL finished) { [self.maskLayer removeFromSuperview]; [self.popView removeFromSuperview]; [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor]; }]; }];}- (CATransform3D)getFirstTransform { CATransform3D transform = CATransform3DIdentity; transform.m34 = 1.0 / -900.0; transform = CATransform3DScale(transform, 0.95, 0.95, 1); transform = CATransform3DRotate(transform, (15.0*M_PI/180.0), 1, 0, 0); transform = CATransform3DTranslate(transform, 0, 0, -100.0); return transform;}- (CATransform3D)getSecondTransform { CATransform3D transform = CATransform3DIdentity; transform.m34 = [self getFirstTransform].m34; transform = CATransform3DScale(transform, 0.8, 0.8, 1.0); transform = CATransform3DTranslate(transform, 0, self.view.frame.size.height * -0.08, 0); return transform;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end