史上最簡單的抽屜效果實(shí)現(xiàn) -- 代碼就是呆萌任性
1、主要控件:Container View
2、實(shí)現(xiàn)思路:通過輕拂手勢(左,右)改變Container View的頂部約束,寬度約束,底部約束
3、實(shí)現(xiàn)代碼:
(1)為了方便,用的模板布局,示意圖如下:
(2)極少代碼
1、拖線出來的三個約束變量
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *Toplayconst;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *Bottomlayconst;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *Widthlayconst;
2、左右輕佛手勢具體實(shí)現(xiàn)代碼
- (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];
}];
}