masonry布局后使用UIView动画

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NLYNN/article/details/81258436

masonry布局后使用UIView动画

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    _testView = [[UIView alloc] init];
    _testView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_testView];
    [_testView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(100);
    }];
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    // 向右平移100
    [_testView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(100);
    }];
    [UIView animateWithDuration:1 animations:^{
        [self.view layoutIfNeeded];
    }];
}

猜你喜欢

转载自blog.csdn.net/NLYNN/article/details/81258436