Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UIScrollView not scrolling but responding to setContentOffset and Delegate responds

Getting a really bizarre incident with a UIScrollView here which just refuses to scroll. I set it up in my StoryBoard and set the contentSize correctly in my ViewDidLoad. I double checked to ensure that it was Scrollable etc, yet it's just not working. I set scrollView.setContentOffset() and it scrolls fine with a lovely animation and the ScrollViewDidScroll delegate get's called. So, with that said any reason why it may not be scrolling with drag gestures?

Things I've checked:
- UserInteraction Enabled on itself, all sub/superviews.
- Scrollable.
- Toggled: DelaysContentTouches and CancellableContentTouches.

I'm out of ideas. Currently using Xcode 6 Beta 1. Any help would be appreciated.

Regards,
Mike

like image 332
Mackey18 Avatar asked Jul 10 '14 18:07

Mackey18


1 Answers

It isn't scrolling with drag gestures because of auto layout. In viewDidLoad, auto layout will reset the content size after you define it. You have two options: you can disable auto layout, or you can set contentSize in viewDidLayoutSubviews.

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    scrollView.contentSize = CGSize(width:10, height:10)
}
like image 167
trumpeter201 Avatar answered Oct 20 '22 18:10

trumpeter201