iOS Masonry 使用小结

2019-06-22  本文已影响0人  CaptainRoy
-(UIView *)redView
{
    if (!_redView) {
        _redView = [[UIView alloc] init];
        _redView.backgroundColor = [UIColor redColor];
        [self.view addSubview:_redView];
        [_redView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(60.0f);
            make.top.offset(64.0f);
            make.right.offset(-10.0f);
        }];
    }
    return _redView;
}

-(UIView *)blueView
{
    if (!_blueView) {
        __weak typeof(self) weakSelf = self;
        _blueView = [[UIView alloc] init];
        _blueView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:_blueView];
        [_blueView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(70.0f);
            make.right.offset(-10.0f);
            make.top.equalTo(weakSelf.redView.mas_bottom).offset(10.0f);
        }];
    }
    return _blueView;
}
-(UIView *)orangeView
{
    if (!_orangeView) {
        _orangeView = [[UIView alloc] init];
        _orangeView.backgroundColor = [UIColor orangeColor];
        [self.view addSubview:_orangeView];
        [_orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.mas_equalTo(100.0f);
            make.left.offset(100.0f);
            make.top.offset(100.0f);
        }];
    }
    return _orangeView;
}
__weak typeof(self) weakSelf = self;
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0/*延迟执行时间*/ * NSEC_PER_SEC));
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.0f animations:^{
            [weakSelf.orangeView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.offset(-50.0f);
            }];
            // 告知父类控件绘制,否则动画无法无法生效
            [weakSelf.orangeView.superview layoutIfNeeded];
        }];
    });
上一篇下一篇

猜你喜欢

热点阅读