美文网首页
Masonry布局二

Masonry布局二

作者: 我想走走 | 来源:发表于2016-12-05 10:02 被阅读13次
    2016-12-05 10_02_23.gif

    更新约束。

    //
    //  ViewController.m
    //  MasonrySecond
    //
    //  Created by mibo02 on 16/12/5.
    //  Copyright © 2016年 mibo02. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "Masonry.h"
    @interface ViewController ()
    
    @property (nonatomic, strong)UIButton *growingButton;
    @property (nonatomic, assign)CGFloat scacle;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        self.growingButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [self.growingButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.growingButton setTitle:@"点击放大" forState:(UIControlStateNormal)];
        self.growingButton.layer.borderColor = [UIColor greenColor].CGColor;
        self.growingButton.layer.borderWidth = 3;
        [self.view addSubview:self.growingButton];
    //    [self.growingButton mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.center.mas_equalTo(self.view);
    //        //优先级最低
    //        make.width.height.mas_equalTo(100*self.scacle).priorityLow();
    //        //放大到整个view上
    //        make.width.height.lessThanOrEqualTo(self.view);
    //    }];
        
    }
    //限制
    - (void)updateViewConstraints
    {
        [self.growingButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(self.view);
            //
            make.width.height.mas_equalTo(100 * self.scacle).priorityLow();
            //
            make.width.height.lessThanOrEqualTo(self.view);
        }];
        [super updateViewConstraints];
    }
    - (void)clickBtnAction:(UIButton *)sender
    {
        self.scacle += 0.5;
        //告诉self.view约束需要更新
        [self.view setNeedsUpdateConstraints];
        //告诉view需要更新的时候在进行更新
        [self.view updateConstraintsIfNeeded];
        [UIView animateWithDuration:0.5 animations:^{
            [self.view layoutIfNeeded];
        }];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    @end
    

    相关文章

      网友评论

          本文标题:Masonry布局二

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