Objective c ScrollView非子视图与autolayout不交互

Objective c ScrollView非子视图与autolayout不交互,objective-c,uiscrollview,autolayout,Objective C,Uiscrollview,Autolayout,我构建了一个“StackView”,因此在滚动视图上添加视图会更容易一些,看起来是这样的: @implementation StackViewAutoLayout { UIView *lastView; UIView *contentView; double contentHight; } -(void) setupContentView { contentView = [[UIView alloc] init]; contentView.userIn

我构建了一个“StackView”,因此在滚动视图上添加视图会更容易一些,看起来是这样的:

@implementation StackViewAutoLayout {
    UIView *lastView;
    UIView *contentView;
    double contentHight;
}

-(void) setupContentView {

    contentView = [[UIView alloc] init];
    contentView.userInteractionEnabled = YES;
    [self addSubview:contentView];

    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];

    contentHight = 0;
}

- (void)addSubviewWithLayout:(UIView *)view {

    if (!contentView) {

        [self setupContentView];
    }

    [contentView addSubview:view];

        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView ? lastView.mas_bottom : @0);
            make.left.equalTo(@0);
            make.width.equalTo(@([UIScreen mainScreen].bounds.size.width));
            make.height.equalTo(@(view.height));
        }];


    view.userInteractionEnabled = YES;
        lastView = view;

    contentHight +=  view.height;

    [contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(contentHight));
    }];

}
我是这样使用它的:

self.overViewScroll = [StackViewAutoLayout new];

[self addSubview:self.overViewScroll];

[self.overViewScroll mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.equalTo(self.mas_left);
            make.right.equalTo(self.mas_right);
            make.top.equalTo(self.headerViewModel.view.mas_bottom);
            make.bottom.equalTo(self.mas_bottom);
}];

[self.overViewScroll addSubviewWithLayout:self.stockDetailsViewModel.view];
[self.overViewScroll addSubviewWithLayout:self.chartViewModel.view];
[self.overViewScroll addSubviewWithLayout:self.summeryViewModel.view];
[self.overViewScroll addSubviewWithLayout:self.postSomthing];

[self setViewStateAccourdingToSwitch];
布局很漂亮,完全符合我的要求。 问题是,修女添加的视图并没有使用指导

我该怎么做才能解决这个问题呢?

找到了一种解决方法

@implementation StackViewAutoLayout {
    UIView *lastView;
    double contentHight;
}

-(void) setupContentView {
    contentHight = 0;

    [self setDelaysContentTouches:NO];
    self.canCancelContentTouches = NO;
}

- (void)addSubviewWithLayout:(UIView *)view {

    [self addSubview:view];

        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lastView ? lastView.mas_bottom : @0);
            make.left.equalTo(@0);
            make.width.equalTo(@([UIScreen mainScreen].bounds.size.width));
            make.height.equalTo(@(view.height));
        }];


    view.userInteractionEnabled = YES;
        lastView = view;

    contentHight +=  view.height;

    self.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, contentHight);

}