How to turn off diagonal scrolling but still be able to scroll horizontally and vertically

I have a problem with scroll view. I can scroll up and down to the left, but sometimes the scroll view decides to pan diagonally. Directional lock is on and for some reason it doesn't help. Actually I finally came up with a way to fix this, now when I scroll to the right or left (FYI: I have paging enabled) the current page before it moves glitches and scrolls to the top, because I set the content height to 0 when contentOffset.x becomes> than 1. Is there a way to fix this or come to it from a different angle? Please help! Heres my "semi-success" if you ..

// 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
    }
}

      

+3


source to share





All Articles