My UIScrollView wont scroll down. I dont 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)
}
Please advice. Thank you.
I do not know it is a good solution, but you can try to set headerview to empty UITableView.
You need to set the
frame
of yourUIScrollView
so that it is less than thecontentsize
. Otherwise, it won't scroll.Also, I would recommend that you add
scroller.contentSize = CGSizeMake(400, 2300)
to yourviewDidLoad
method.If you use AutoLayout,
Set content size in viewdidAppear which works for me.
override func viewDidAppear(_ animated: Bool) {
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 :-)
This code will work perfectly fine as long as you do what I said up above
Swift 3.0 version
If you are using autolayout, then the contentSize property stops working and it will try to infer the content size from the constraints. If that is the case, then your problem could be that you are not defining the necessary constraints to the content view so that the scrollview can infer the content size. You should define the constraints of your content view to the top and bottom edges of the scrollview.