how to disable diagonal scrolling but still be able to scroll horizontally and vertically

2.5k views Asked by At

Im having a problem with my scroll view. I can scroll up to down and left to right but sometimes the scroll view decides to pan diagonally. Direction Lock is turned on which does not help for some reason. I actually did finally come up with a way to fix it however, now when ever I scroll to the right or left (FYI: I have paging enabled) the current page before it transitions glitches and scrolls to the top because I had set the content height to 0 when the contentOffset.x becomes > than 1. Is there any way I can fix this or come at it from a different angle? Please help! Heres my "semi-success" if you will..

// MARK: Scroll view delegate methods
func scrollViewDidScroll(scrollView: UIScrollView) {
    self.scrollView.contentSize.height = 1000
    self.scrollView.contentSize.width = scrollView.bounds.width * 2
    self.scrollView.bounces = false
    if self.scrollView.contentOffset.x > 1 {
        self.scrollView.pagingEnabled = true
        self.scrollView.contentSize.width = scrollView.bounds.width * 2
        self.scrollView.contentSize.height = 0
    }
    if self.scrollView.contentOffset.y > 1 {
        self.scrollView.pagingEnabled = false
    }
    if self.scrollView.contentOffset.x >= self.scrollView.frame.width {
            self.pageController.currentPage = 1
    }
    else {
        self.pageController.currentPage = 0
        self.scrollView.contentSize.height = 1000
        self.scrollView.scrollsToTop = false
    }
}
0

There are 0 answers