Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView not scrolling in Swift

My UIScrollView won't scroll down. I don't know why. I already followed Apple documentation regarding to this issue.

@IBOutlet weak var scroller: UIScrollView!      override func viewDidLoad() {     super.viewDidLoad()      // Do any additional setup after loading the view.  }  override func viewDidLayoutSubviews() {     scroller.scrollEnabled = true     // Do any additional setup after loading the view     scroller.contentSize = CGSizeMake(400, 2300) } 
like image 248
Nurdin Avatar asked Jan 26 '15 04:01

Nurdin


People also ask

Why scroll view not working in Swift?

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

Why is ScrollView 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.

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

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

Also, I would recommend that you add the following to your viewDidLoad method:

scroller.contentSize = CGSize(width: 400, height: 2300) 
like image 152
Christian Avatar answered Sep 22 '22 01:09

Christian


Alot of the time the code is correct if you have followed a tutorial but what many beginners do not know is that the scrollView is NOT going to scroll normally through the simulator. It is suppose to scroll only when you press down on the mousepad and simultaneously scroll. Many Experienced XCode/Swift/Obj-C users are so use to doing this and so they do not know how it could possibly be overlooked by beginners. Ciao :-)

@IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() view.addSubview(scrollView) // Do any additional setup after the view }  override func viewWillLayoutSubviews(){ super.viewWillLayoutSubviews() scrollView.contentSize = CGSize(width: 375, height: 800) } 

This code will work perfectly fine as long as you do what I said up above

like image 25
flo527 Avatar answered Sep 23 '22 01:09

flo527