更新约束。
//
// 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
网友评论