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

2016-10-14  本文已影响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];

}];

}

上一篇下一篇

猜你喜欢

热点阅读