利用bounds实现侧滑

1 篇文章 0 订阅
//侧滑出现
UIWindow *window = [[UIApplication sharedApplication] keyWindow];

    CGFloat windowWidth = [UIScreen mainScreen].bounds.size.width;//屏幕宽度
    CGFloat windowHeight = [UIScreen mainScreen].bounds.size.height;//屏幕高度
    CGFloat leftWidth = windowWidth * 0.64;//侧滑view的宽度
    CGFloat zoomHeight = 20;//主界面缩放高度

    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(-leftWidth, -zoomHeight, leftWidth, windowHeight + zoomHeight * 2)];
    [leftView setBackgroundColor:[UIColor blueColor]];
    [window addSubview:leftView];

    CALayer *backLayer = [CALayer layer];
    [backLayer setAnchorPoint:CGPointZero];
    [backLayer setPosition:leftView.frame.origin];
    [backLayer setBounds:CGRectMake(0, 0, windowWidth + CGRectGetWidth(leftView.frame), CGRectGetHeight(leftView.frame))];
    [backLayer setBackgroundColor:[UIColor yellowColor].CGColor];
    [window.layer insertSublayer:backLayer atIndex:0];//背景放到最下方

    //改变bounds,侧滑出现
    [UIView animateWithDuration:2 animations:^{
        [window setBounds:CGRectMake(CGRectGetMinX(leftView.frame),  0, windowWidth, windowHeight - zoomHeight * 2)];
    }];
//侧滑消失
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [UIView animateWithDuration:2 animations:^{
        [window setBounds:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    }];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值