7
votes

Well, I know that there is already many answers to my questions but I've tested each one of these and I still have the problem. I have a UIScrollView wich 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 ?

1
Are the scrollView and the containerScrollView different sizes? If they are the same size, the contentSize of the scroll view will dictate that no scrolling is necessary to view all of the content.Eric
Yes, size is different. _scrollview height : 652. _containerScrollView height : 1050Maxime
In autolayout, you generally don't specify the contentSize of a scroll view, because it is generally dictated by the constraints of the subviews. But, stepping back from that, perhaps you can just tell us what you're trying to achieve. It's hard to recommend solutions without understanding the bigger picture of the desired UX. E.g., what is the nature of the animation? How did you define the constraints of _containerScrollView (which I assume is a UIView inside the scroll view, not a UIScrollView itself)?Rob
Well, the containerScrollView is a UIView which contains many UIViews. Actually, it's a right slide bar with many filters to display or not markers on a fullscreen map. In this slide bar I've a multiselect list. The aim of the animation is that when i tap on multiselect, the list slide down and views placed under, scroll too. To avoid that multiselect list come on foreground over filtersMaxime

1 Answers

7
votes

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)];
}