美文网首页
10.2 Masonry按钮动画

10.2 Masonry按钮动画

作者: 草根小强 | 来源:发表于2019-04-25 17:24 被阅读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

    相关文章

      网友评论

          本文标题:10.2 Masonry按钮动画

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