Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uiscrollview doesn't scroll because of autolayout

I know that there are already many answers to my questions, but I've tested each one of these and I still have the problem. I have a UIScrollView which contains a UIView, I want active autolayout for an animation. But because of this, my scrollview doesn't scroll.

This is my code:

NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_scrollView, _containerScrollView);
    
    [_scrollView setScrollEnabled:YES];
    [_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width, CGRectGetHeight(_containerScrollView.frame))];
    _scrollView.userInteractionEnabled = YES;
    _scrollView.delaysContentTouches = YES;
    
    [self.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_scrollView]|" options:0 metrics:0 views:viewsDictionary]];
    [self.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_scrollView]|" options:0 metrics:0 views:viewsDictionary]];
    [_scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_containerScrollView]|" options:0 metrics:0 views:viewsDictionary]];
    [_scrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_containerScrollView]|" options:0 metrics:0 views:viewsDictionary]];

Somebody can explain me why doesn't it work?

like image 805
Maxime Avatar asked Aug 21 '13 14:08

Maxime


1 Answers

Try to set your scrollView's Content size int "viewDidLayoutSubviews" method with keeping the autolayouts set.

-(void)viewDidLayoutSubviews
{
  [self.itemList setContentSize:CGSizeMake(required_width, required_height)];
}
like image 88
Hanny Avatar answered Nov 18 '22 06:11

Hanny