10.2 Masonry按钮动画

2019-04-25  本文已影响0人  草根小强

Masonry按钮动画

#import "ViewController.h"
#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor purpleColor];
    btn.layer.borderColor = [UIColor greenColor].CGColor;
    btn.layer.borderWidth = 2.0;
    [btn setTitle:@"点击放大" forState:UIControlStateNormal];
    
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        //居中
        make.center.mas_equalTo(self.view);
        make.width.height.mas_equalTo(80);
        make.width.height.lessThanOrEqualTo(self.view);
    }];
    
}

- (void)clickBtn:(UIButton *)btn{
    
    static CGFloat padding = 0;
    padding += 0.5;
    //删除旧约束 更新新约束 可以使用uapdata
    [btn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.view);
        //priorityLow()优先级250  priorityHigh优先级750
        make.height.width.mas_equalTo(80+80*padding).priority(251);
        //lessThanOrEqualTo 最大值是多少
        make.width.height.lessThanOrEqualTo(self.view);
    }];
    
    [self.view setNeedsUpdateConstraints];
    [self.view updateConstraintsIfNeeded];
    
    
    [UIView animateWithDuration:0.5 animations:^{
        // 立即实现布局
        [self.view layoutIfNeeded];
    }];
    
    //animateWithDuration 动画持续时间
    // animations 为动画效果的代码块
    // completion 动画执行完以后执行的代码块
//    UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>
}
@end
Masonry按钮动画1.png
Masonry按钮动画2.png
上一篇下一篇

猜你喜欢

热点阅读