I have a UIScrollView
which contains many UIImageView
s, UILabels, etc... the labels are much longer that the UIScrollView
, but when I run the app, I cannot click and scroll down...
Why might this be?
Thanks
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.
You need to set the frame of your UIScrollView so that it is less than the contentSize . Otherwise, it won't scroll.
One way to do this is programmatically create an UIScrollView in your UIViewController . To control the scrollability you can set the ScrollView contentSize property.
It's always good to show a complete working code snippet:
// in viewDidLoad (if using Autolayout check note below): UIScrollView *myScrollView; UIView *contentView; // scrollview won't scroll unless content size explicitly set [myScrollView addSubview:contentView];//if the contentView is not already inside your scrollview in your xib/StoryBoard doc myScrollView.contentSize = contentView.frame.size; //sets ScrollView content size
Swift 4.0
let myScrollView let contentView // scrollview won't scroll unless content size explicitly set myScrollView.addSubview(contentView)//if the contentView is not already inside your scrollview in your xib/StoryBoard doc myScrollView.contentSize = contentView.frame.size //sets ScrollView content size
I have not found a way to set contentSize in IB (as of Xcode 5.0).
Note: If you are using Autolayout the best place to put this code is inside the -(void)viewDidLayoutSubviews
method .
If you cannot scroll the view even after you set contentSize correctly, make sure you uncheck "Use AutoLayout" in Interface Builder -> File Inspector.
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