Masonry布局三

Masonry布局三_第1张图片
2016-12-05 10_20_42.gif
//
//  NewViewController.m
//  MasonrySecond
//
//  Created by mibo02 on 16/12/5.
//  Copyright © 2016年 mibo02. All rights reserved.
//

#import "NewViewController.h"
#import "Masonry.h"
@interface NewViewController ()

@property (nonatomic, strong)UIButton *growingButton;
@property (nonatomic, assign)BOOL isExpanded;

@end

@implementation NewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.growingButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.growingButton setTitle:@"点我展开" forState:(UIControlStateNormal)];
    self.growingButton.layer.borderWidth = 3;
    self.growingButton.layer.borderColor = [UIColor redColor].CGColor;
    self.growingButton.backgroundColor = [UIColor greenColor];
    [self.growingButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:self.growingButton];
    self.isExpanded = NO;
    
}
//
- (void)updateViewConstraints
{
    [super updateViewConstraints];
    [self.growingButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
        if (self.isExpanded) {
            make.bottom.mas_equalTo(0);
        } else {
            make.bottom.mas_equalTo(-350);
        }
    }];
}

- (void)clickBtnAction:(UIButton *)sender
{
    self.isExpanded = !self.isExpanded;
    if (!_isExpanded) {
        [self.growingButton setTitle:@"点我展开" forState:(UIControlStateNormal)];
    } else {
        [self.growingButton setTitle:@"点我收起" forState:(UIControlStateNormal)];
    }
    [self.view setNeedsUpdateConstraints];
    [self.view updateConstraintsIfNeeded];
    [UIView animateWithDuration:0.3 animations:^{
        [self.view layoutIfNeeded];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

你可能感兴趣的:(Masonry布局三)