I have a UIViewController with a UIScrollView I've added in Interface Builder. I want to have scrollView functions so I can detect if it's been scrolled up or down. My scroll view is attached with an IBOutlet called "mainScroll." Here is my code:
var lastContentOffset: CGFloat = 0
@IBOutlet weak var mainScroll: UIScrollView!
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.lastContentOffset = mainScroll.contentOffset.y
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (self.lastContentOffset < mainScroll.contentOffset.y) {
// did move up
print("Did Move Up")
} else if (self.lastContentOffset > mainScroll.contentOffset.y) {
// did move down
print("Did Move Down")
} else {
// didn't move
}
}
I've added UIScrollViewDelegate to my class. I have a feeling I'm not using the scrollView delegate callbacks properly. How can I take these functions and assign them to my "mainScroll"?