Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto layout UIScrollView with subviews with dynamic heights
    primarykey
    data
    text
    <p>I'm having troubles with UIScrollView using auto layout constraints. I have the following view hierarchy, with constraints set through IB:</p> <pre><code>- ScrollView (leading, trailing, bottom and top spaces to superview) -- ContainerView (leading, trailing, bottom and top spaces to superview) --- ViewA (full width, top of superview) --- ViewB (full width, below ViewA) --- Button (full width, below ViewB) </code></pre> <p>The ViewA and ViewB have initial heights of 200 points, but it can be expended vertically to an height of 400 points by clicking on it. ViewA and ViewB are expanded by updating their height constraint (from 200 to 400). Here is the corresponding snippet :</p> <pre><code>if(self.contentVisible) { heightConstraint.constant -= ContentHeight; // + additional View's internal constraints update to hide additional content self.contentVisible = NO; } else { heightConstraint.constant += ContentHeight; // + additional View's internal constraints update to show additional content self.contentVisible = YES; } [self.view setNeedsUpdateConstraints]; [UIView animateWithDuration:.25f animations:^{ [self.view layoutIfNeeded]; }]; </code></pre> <p>My problem is that if both views are expanded, I need to be able to scroll to see the whole content, and right now the scroll is not working. How can I manage to update the scroll view using constraints to reflect the changes of ViewA and ViewB heights ?</p> <p>The only solution I can think of so far is to manually set the height of the ContainerView after the animation, which will be the sum of the heights of ViewA + ViewB + Button. But I believe there is a better solution?</p> <p>Thanks</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