美文网首页
史上最简单的抽屉效果--只要极少的代码实现

史上最简单的抽屉效果--只要极少的代码实现

作者: 心如止水的鱼 | 来源:发表于2016-10-14 09:38 被阅读0次

    史上最简单的抽屉效果实现 -- 代码就是呆萌任性

    实现效果展示

    1、主要控件:Container View

    2、实现思路:通过轻拂手势(左,右)改变Container View的顶部约束,宽度约束,底部约束

    3、实现代码:

    (1)为了方便,用的模板布局,示意图如下:


    (2)极少代码

    1、拖线出来的三个约束变量

    @property (strong, nonatomic) IBOutlet NSLayoutConstraint *Toplayconst;

    @property (strong, nonatomic) IBOutlet NSLayoutConstraint *Bottomlayconst;

    @property (strong, nonatomic) IBOutlet NSLayoutConstraint *Widthlayconst;

    2、左右轻佛手势具体实现代码

    - (IBAction)Swipleft:(UISwipeGestureRecognizer *)sender {

    self.Toplayconst.constant = 0;

    self.Bottomlayconst.constant = 0;

    self.Widthlayconst.constant = self.view.bounds.size.width;

    [UIView animateWithDuration:0.5 animations:^{

    [self.view layoutIfNeeded];

    }];

    }

    - (IBAction)Swipright:(UISwipeGestureRecognizer *)sender {

    self.Toplayconst.constant = 40;

    self.Bottomlayconst.constant = 40;

    self.Widthlayconst.constant = 100;

    [UIView animateWithDuration:0.5 animations:^{

    [self.view layoutIfNeeded];

    }];

    }

    相关文章

      网友评论

          本文标题:史上最简单的抽屉效果--只要极少的代码实现

          本文链接:https://www.haomeiwen.com/subject/srygyttx.html