View ios 8 Xcode not Scrolling - Swift
I am very new to Swift and developing on ios, but I cannot find a way to get the UIScrollView to scroll down and stay in place. I have tried tons of tutorials on this and nothing so far. I have a ContentView inside my ScrollView. This ContentView has all my boxes that I want to scroll, but it doesn't scroll. It does bounce though, if it matters ... can anyone send me in the right direction?
source to share
It looks like you might not have set contentSize
for your scroll. To do this, if you are not using automatic layout:
scrollView.contentSize = // The size of your content.
If you are using an automatic layout, you need to make sure you have it NSLayoutConstraints
from every edge of your content to every corresponding edge of yours UIScrollView
. This UIScrollView
will automatically size your content .
Hope it helps.
source to share
Just wanted to add a note to FreeTheStudentsAnswer in case anyone had a similar problem - I set the scrollView to screen size and then set the content view height to a higher value and only started working when I set that to viewDidAppear instead of viewDidLoad. Not sure if this will help anyone, but it fixed my problem.
source to share
In a scrollview, scrolling occurs only if there is enough space for the scroll to scroll the content.
You said the scrollview and its content are the same size. Then it won't scroll. Scrollview.contentSize must be at least half the size of the scroll if you want to scroll.
Tip: Scroll should not be larger than the iPhone screen. The scroll content must be larger than the scrollview. Scrolling allows you to scroll the contents of your content.
source to share
SWIFT 4.0 update
@IBOutlet weak var myScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
myScrollView.alwaysBounceVertical = true
myScrollView.alwaysBounceHorizontal = true
myScrollView.isScrollEnabled = true
myScrollView.contentSize = CGSize(width: 375, height: 1000)
}
source to share