2015-03-29 5 views
0

Я построить «StackView» так добавляющие взгляды на вид прокрутки будет немного более легким, он выглядит так:Scrollview не подвиды не Интеракционная с autolayout

@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]; 

Расположение красиво и точно именно я искал. Проблема в том, что монахиня добавленных представлений не является учебной!

Что мне делать, чтобы исправить это?

ответ

0

Найден способ это работает

@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); 

} 
Смежные вопросы