Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView doesn't scroll - even with valid content size and scroll enabled
    primarykey
    data
    text
    <p>In my <code>viewDidAppear</code> method (in which i call to the super method) I have the following code:</p> <pre><code>UIScrollView *navbar = [[UIScrollView alloc] init]; [navbar setScrollEnabled:YES]; [navbar setBackgroundColor:[UIColor redColor]]; [navbar setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.view addSubview:navbar]; NSDictionary *viewsDictionary2 = NSDictionaryOfVariableBindings(navbar); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[navbar]|" options:0 metrics:nil views:viewsDictionary2]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[navbar]|" options:0 metrics:nil views:viewsDictionary2]]; NSArray *categories = @[@"nav1", @"nav2", @"nav3", @"nav4", @"nav5", @"nav6", @"nav7", @"nav8", @"nav9", @"nav10", @"nav11", @"nav12", @"nav13"]; NSMutableArray *tempCategoryImages = [NSMutableArray array]; for (NSInteger i = 0; i &lt; categories.count; i++) { [tempCategoryImages insertObject:[UIImage imageNamed:categories[i]] atIndex:i]; } NSArray *categoryImages = [tempCategoryImages copy]; // Add subviews. // CGFloat xPadding = 25.0f; UIView *previousImageView = NULL; for (NSInteger i = 0; i &lt; categoryImages.count; i++) { UIImageView *imageView = [[UIImageView alloc] initWithImage:categoryImages[i]]; [imageView setTranslatesAutoresizingMaskIntoConstraints:NO]; [navbar addSubview:imageView]; if (i == 0) { // // First category. // [navbar addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:imageView.superview attribute:NSLayoutAttributeLeft multiplier:1 constant:0]]; } else { // // End categories. // [navbar addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:previousImageView attribute:NSLayoutAttributeRight multiplier:1 constant:xPadding]]; } [navbar addConstraint:[NSLayoutConstraint constraintWithItem:imageView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:imageView.superview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]]; previousImageView = imageView; } // Set content size. // CGSize scrollContentSize = CGSizeZero; for (NSInteger i = 0; i &lt; categories.count; i++) { UIImage *tempImage = [UIImage imageNamed:categories[i]]; // Width. // scrollContentSize.width += tempImage.size.width; // Height. // if (tempImage.size.height &gt; scrollContentSize.height) { scrollContentSize.height = tempImage.size.height; } } navbar.contentSize = scrollContentSize; </code></pre> <p>Which when i log the scrollviews properties, it has the subviews, a large enough content size and scrolling enabled.</p> <p>Even when I add the <code>UIScrollView</code> to IB and link it to the same code it then works? (I comment out the <code>NSAutoLayout</code> code.</p> <p>This leads me to believe that for the UIScrollView to work, I cannot use Auto layout.</p> <p>Am I missing something?</p> <p>Thanks </p> <p><em><strong>EDIT</em></strong></p> <p>The code also doesn't work programatically, when I try <code>initWithFrame:</code><em>frame</em> with <code>setTranslatesAutoresizingMaskIntoConstraints:YES</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload