objective-c - iOS开发中 --> 关于使用Masonry去自适应ScrollView滚动视图内容的一些疑问!!!
怪我咯
怪我咯 2017-04-18 09:29:46
0
3
446
  • 一般滚动视图ScrollView上下滑动式,使用Masonry可以去自适应内容大小,只要在最后一个控件后面增加一些ScrollView的约束即可,比如:

[_personCenterScrollView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
        make.bottom.mas_equalTo(_EquipmentView.bottom).with.offset(5*Padding);
    }];

这样就可以去自适应ScrollView内容多少,有多少都不怕。

2.问题来了:

  • 我想横向使用ScrollView那么我的内容是否也可以自适应-->(这个问题我整不出来,呜~~)

  • 纵向使用ScrollView时用到 bottom 这个限制属性去约束ScrollView的内容,那么横向我是否可以使用 right 这个显示属性去约束ScrollView的内容呢?

[_personCenterScrollView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
        make.right.mas_equalTo(_EquipmentView.right).with.offset(5*Padding);
    }];

我现在没整出来,我考虑过一些原因:

  • 使用self.view去限制滚动视图中 控件 的左右边距;

  • 我的Masnory版本太低了,没有更高的版本;

  • 最后恳亲大家帮忙,这个问题困扰我好久了。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
伊谢尔伦

First of all, when using constraints in sv, you must determine the size (constraints) of the internal controls and then determine the margin relationship between the internal controls and sv.

For example: if a view is in sv, first determine the margins between the view and sv, and then determine the width and height of the view.

If there are multiple views side by side. You determine the width, height, and margins of the views

阿神

The horizontal and vertical writing methods are similar. There should be no problem with the grammar of the two Masnory sentences above. You can find out if there are other reasons. I feel that it should not be a version problem, but you can try updating it.

迷茫
参考一下下面的写法:
self.automaticallyAdjustsScrollViewInsets = NO;
__weak __typeof(self) weakSelf = self;
UIView *sv = [UIView new];
sv.backgroundColor = [UIColor blackColor];
[self.view addSubview:sv];
[sv mas_makeConstraints:^(MASConstraintMaker *make) {
    make.center.equalTo(weakSelf.view);
    make.size.mas_equalTo(CGSizeMake(300, 300));
}];

UIScrollView *scrollView = [UIScrollView new];
scrollView.backgroundColor = [UIColor whiteColor];
[sv addSubview:scrollView];

[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(sv).insets(UIEdgeInsetsMake(5, 5, 5, 5));
}];
UIView *container = [UIView new];
[scrollView addSubview:container];

[container mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(scrollView);
    make.height.equalTo(scrollView);
}];

int count = 10;
UIView *lastView = nil;
for (int i = 1; i < count; i++) {
    UIView *subV = [UIView new];
    [container addSubview:subV];
    subV.backgroundColor = [UIColor colorWithRed:(arc4random() % 256 / 256.0)
                                           green:(arc4random() % 256 / 256.0)
                                            blue:(arc4random() % 256 / 256.0)
                                           alpha:1];
    [subV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(container);
        make.width.mas_equalTo(20 * i);
        if (lastView) {
            make.left.mas_equalTo(lastView.mas_right);
        }else{
            make.left.mas_equalTo(container.mas_left);
        }
    }];
    
    lastView = subV;
}
[container mas_updateConstraints:^(MASConstraintMaker *make) {
    make.right.mas_equalTo(lastView.mas_right);
}];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template