博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
仿淘宝选择规格动画效果
阅读量:7043 次
发布时间:2019-06-28

本文共 3845 字,大约阅读时间需要 12 分钟。

hot3.png

 

#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

 

转载于:https://my.oschina.net/zsyzone/blog/1438807

你可能感兴趣的文章
iOS程序执行顺序和UIViewController 的生命周期(整理)
查看>>
.如何将页脚固定在页面底部
查看>>
java swing awt初级入门
查看>>
Ubuntu闪电入门第一弹
查看>>
swift语言--输入输出参数
查看>>
php小代码(1)
查看>>
Java面试宝典(5)算法
查看>>
android suport respository和Android Support Library
查看>>
ubuntu16.04 配置DOCKER_OPS
查看>>
Cisco技术区常用配置实例整理(1)
查看>>
DirectionGUI
查看>>
Android用户体验毁在框架设计?
查看>>
JavaScript中一些常用API使用方法简析
查看>>
Android Google Map API使用的八个步骤
查看>>
ISA server 限制访问和开放内部资源及系统维护
查看>>
javascript计算前1!+2!+...+n!的阶乘和
查看>>
SCOM2012–Part3 如何监控群集
查看>>
我的友情链接
查看>>
Ruby+watir 自动化测试
查看>>
我的Python学习记录-python初次接触
查看>>