I put a UIScrollView
in my nib's view
, and linked it to a an IBOutlet
property.
Now, when I do this in my viewDidLoad
method, it seems to have no effect on the contentSize
:
self.sv.backgroundColor = [UIColor yellowColor]; // this works CGSize size = CGSizeMake(1000.0, 1000.0); [self.sv setContentSize:size]; // this does not
It behaves as if the contentSize
was the same as the frame. What's going on? This started working when I turned off AutoLayout. Why?
To fix ScrollView Not scrolling with React Native, we wrap the content of the ScrollView with the ScrollView. to wrap ScrollView around the Text components that we render inside. As a result, we should see text inside and we can scroll up and down.
Add a UIStackView to the UIScrollView. Set the constraints: Leading , Trailing , Top & Bottom should be equal to the ones from UIScrollView. Set up an equal Width constraint between the UIStackView and UIScrollView . Set Axis = Vertical, Alignment = Fill, Distribution = Equal Spacing, and Spacing = 0 on the UIStackView.
I had the same problem. Auto Layout for UIScrollView
is messed up.
Work around: Put everything in the UIScrollView
into another UIView
, and put that UIView
as the only child of the UIScrollView
. Then you can use Auto Layout.
If things near the end is messed up (the end of whichever direction your UIScrollView
scrolls), change the constraint at the end to have the lowest possible priority.
I tried viewWillLayoutSubviews to update scrollView's contentSize, it worked for me.
- (void)viewDidLayoutSubviews { [self.bgScrollView setContentSize:CGSizeMake(320, self.view.frame.size.height* 1.5)]; }
Apple Doc
-(void)viewDidLayoutSubviews
Called to notify the view controller that its view has just laid out its subviews.
Discussion
When the bounds change for a view controller’s view, the view adjusts the positions of its subviews and then the system calls this method. However, this method being called does not indicate that the individual layouts of the view’s subviews have been adjusted. Each subview is responsible for adjusting its own layout.
Your view controller can override this method to make changes after the view lays out its subviews. The default implementation of this method does nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With