利用bounds实现侧滑

//侧滑出现
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)];
    }];

你可能感兴趣的:(iOS,侧滑,侧滑)