Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView not scrolling until orientation changes
    primarykey
    data
    text
    <p>I have a UIScrollView dynamically added into the main view, and I'm filling it with small UIView objects. I'm setting it's contentSize to something bigger than the device's resolution but I can't scroll it until I'm changing the device's orientation.</p> <p>How can I make it scroll before orientation change ?</p> <p>LATER EDIT :</p> <p>I realized that the problem comes from certain subviews that i'm adding, more specifically from adding some contraints for those subviews:</p> <p>Here is the code where I'm adding the subviews (the method is called about 10-20 times) :</p> <pre><code>-(void) addShelve:(NSInteger) index { FSShelf *shelf = [[FSShelf alloc] initWithFrame:CGRectMake(0, index * [FSConstants getShelfVerticalDistance], 0, 0)]; [shelves addObject:shelf]; [shelfView addSubview:shelf]; [shelf addShelfConstraints]; } </code></pre> <p>FSShelf is a subclass of UIView and shelfView is my subclass of UIScrollView.</p> <p>And here are the constraints added at <code>addShelfContraints</code> :</p> <pre><code> [self.superview addConstraint:[FSUtils getWidthConstraintFor:self.superview with:self constant: -2 * ([FSConstants getShelveMargin])]]; [self addConstraint:[FSUtils getSelfHeightConstraintFor:self constant:30]]; [self.superview addConstraint:[FSUtils getCenterXConstraintFor:self.superview with:self constant:0]]; </code></pre> <p>The methods from the FSUtils class for adding contraints:</p> <pre><code>+ (NSLayoutConstraint *)getSelfHeightConstraintFor:(UIView *)view constant:(CGFloat)constant { NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:constant]; return constraint; } + (NSLayoutConstraint *)getCenterXConstraintFor:(UIView *)superView with:(UIView *)subView constant:(CGFloat)constant { NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:constant]; return constraint; } + (NSLayoutConstraint *)getWidthConstraintFor:(UIView *)superView with:(UIView *)subView constant:(CGFloat)constant { NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:subView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:superView attribute:NSLayoutAttributeWidth multiplier:1.0 constant:constant]; return constraint; } </code></pre> <p>Do you notice anything wrong with those contraints?</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.
 

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