IOS masonry动画

来源:互联网 发布:淘宝推广方式 编辑:程序博客网 时间:2024/06/05 05:25

1.控件的原始约束

self.animationBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];

    [self.animationBtnsetTitle:@"动画按钮"forState:UIControlStateNormal];

    self.animationBtn.backgroundColor=[UIColorgrayColor];

    

    [self.animationBtnaddTarget:selfaction:@selector(onGrowButtonTaped:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:self.animationBtn];

    self.scacle =1.0;

    

    [self.animationBtnmas_makeConstraints:^(MASConstraintMaker *make) {

        make.center.mas_equalTo(self.view);

        make.width.height.mas_equalTo(100);

        make.width.height.lessThanOrEqualTo(self.view);

    }];

2.点击开始做动画的时候从新做约束

- (void)onGrowButtonTaped:(UIButton *)sender {

    [UIViewanimateWithDuration:2animations:^{

        [self.animationBtnmas_remakeConstraints:^(MASConstraintMaker *make){

            make.left.top.equalTo(self.view);

            make.width.height.mas_equalTo(200);

        }];

        [self.viewlayoutIfNeeded];//强制绘制

    }];

    

}


0 0
原创粉丝点击