Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView not scrolling

I have a UIScrollView which contains many UIImageViews, 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

like image 280
Mark Avatar asked May 13 '10 04:05

Mark


People also ask

Why my ScrollView is not scrolling?

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.

Why is my scroll view not scrolling Swift?

You need to set the frame of your UIScrollView so that it is less than the contentSize . Otherwise, it won't scroll.

How do you make a scrollable view in Swift?

One way to do this is programmatically create an UIScrollView in your UIViewController . To control the scrollability you can set the ScrollView contentSize property.


2 Answers

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 .

like image 70
Bogatyr Avatar answered Sep 23 '22 19:09

Bogatyr


If you cannot scroll the view even after you set contentSize correctly, make sure you uncheck "Use AutoLayout" in Interface Builder -> File Inspector.

like image 30
user1539652 Avatar answered Sep 24 '22 19:09

user1539652